Skip to content

Commit

Permalink
restore ambiguity warning test
Browse files Browse the repository at this point in the history
since this did the work in a slightly different order,
a couple existing ambiguity detection flaws were revealed

in ranges, modifying the tvars in the method signature helped to make
the current type system able to resolve this with less ambiguity

in replutil, there was a missing method definition
  • Loading branch information
vtjnash committed Apr 12, 2016
1 parent 70ac55d commit 99d216c
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 147 deletions.
20 changes: 10 additions & 10 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ end

promote_rule{T1,T2}(::Type{UnitRange{T1}},::Type{UnitRange{T2}}) =
UnitRange{promote_type(T1,T2)}
convert{T}(::Type{UnitRange{T}}, r::UnitRange{T}) = r
convert{T}(::Type{UnitRange{T}}, r::UnitRange) = UnitRange{T}(r.start, r.stop)
convert{T<:Real}(::Type{UnitRange{T}}, r::UnitRange{T}) = r
convert{T<:Real}(::Type{UnitRange{T}}, r::UnitRange) = UnitRange{T}(r.start, r.stop)

promote_rule{T1a,T1b,T2a,T2b}(::Type{StepRange{T1a,T1b}},::Type{StepRange{T2a,T2b}}) =
StepRange{promote_type(T1a,T2a),promote_type(T1b,T2b)}
Expand All @@ -681,36 +681,36 @@ convert{T}(::Type{StepRange}, r::UnitRange{T}) =

promote_rule{T1,T2}(::Type{FloatRange{T1}},::Type{FloatRange{T2}}) =
FloatRange{promote_type(T1,T2)}
convert{T}(::Type{FloatRange{T}}, r::FloatRange{T}) = r
convert{T}(::Type{FloatRange{T}}, r::FloatRange) =
convert{T<:AbstractFloat}(::Type{FloatRange{T}}, r::FloatRange{T}) = r
convert{T<:AbstractFloat}(::Type{FloatRange{T}}, r::FloatRange) =
FloatRange{T}(r.start,r.step,r.len,r.divisor)

promote_rule{F,OR<:OrdinalRange}(::Type{FloatRange{F}}, ::Type{OR}) =
FloatRange{promote_type(F,eltype(OR))}
convert{T}(::Type{FloatRange{T}}, r::OrdinalRange) =
convert{T<:AbstractFloat}(::Type{FloatRange{T}}, r::OrdinalRange) =
FloatRange{T}(first(r), step(r), length(r), one(T))
convert{T}(::Type{FloatRange}, r::OrdinalRange{T}) =
FloatRange{typeof(float(first(r)))}(first(r), step(r), length(r), one(T))

promote_rule{T1,T2}(::Type{LinSpace{T1}},::Type{LinSpace{T2}}) =
LinSpace{promote_type(T1,T2)}
convert{T}(::Type{LinSpace{T}}, r::LinSpace{T}) = r
convert{T}(::Type{LinSpace{T}}, r::LinSpace) =
convert{T<:AbstractFloat}(::Type{LinSpace{T}}, r::LinSpace{T}) = r
convert{T<:AbstractFloat}(::Type{LinSpace{T}}, r::LinSpace) =
LinSpace{T}(r.start, r.stop, r.len, r.divisor)

promote_rule{F,OR<:OrdinalRange}(::Type{LinSpace{F}}, ::Type{OR}) =
LinSpace{promote_type(F,eltype(OR))}
convert{T}(::Type{LinSpace{T}}, r::OrdinalRange) =
convert{T<:AbstractFloat}(::Type{LinSpace{T}}, r::OrdinalRange) =
linspace(convert(T, first(r)), convert(T, last(r)), convert(T, length(r)))
convert{T}(::Type{LinSpace}, r::OrdinalRange{T}) =
convert(LinSpace{typeof(float(first(r)))}, r)

# Promote FloatRange to LinSpace
promote_rule{F,OR<:FloatRange}(::Type{LinSpace{F}}, ::Type{OR}) =
LinSpace{promote_type(F,eltype(OR))}
convert{T}(::Type{LinSpace{T}}, r::FloatRange) =
convert{T<:AbstractFloat}(::Type{LinSpace{T}}, r::FloatRange) =
linspace(convert(T, first(r)), convert(T, last(r)), convert(T, length(r)))
convert{T}(::Type{LinSpace}, r::FloatRange{T}) =
convert{T<:AbstractFloat}(::Type{LinSpace}, r::FloatRange{T}) =
convert(LinSpace{T}, r)


Expand Down
9 changes: 6 additions & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,16 +955,19 @@ static int jl_serialize_methcache_from_mod(jl_typemap_entry_t *ml, void *closure

static void jl_serialize_methtable_from_mod(ios_t *s, jl_methtable_t *mt, int8_t iskw)
{
jl_sym_t *name = mt->name;
struct jl_serialize_methcache_from_mod_env env;
env.s = s;
env.mod = mt->module;
env.name = mt->name;
env.iskw = iskw;
assert(mt->module);
if (iskw) {
if (!mt->kwsorter)
return;
assert(mt->module == jl_gf_mtable(mt->kwsorter)->module);
mt = jl_gf_mtable(mt->kwsorter);
assert(!mt->kwsorter);
}
assert(mt->module);
struct jl_serialize_methcache_from_mod_env env = {s, name, mt->module, iskw};
jl_typemap_visitor(mt->defs, jl_serialize_methcache_from_mod, &env);
}

Expand Down
Loading

0 comments on commit 99d216c

Please sign in to comment.