Skip to content

Commit

Permalink
fix "improved" correctness of fieldtype
Browse files Browse the repository at this point in the history
the getfield_tfunc was missing a test for whether
the fields were all equivalent before concluding
that the result type was exact

fixes the fix JuliaLang#17953
fix JuliaLang#18037
  • Loading branch information
vtjnash authored and mfasi committed Sep 5, 2016
1 parent bc3b2a4 commit 1869053
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function getfield_tfunc(s0::ANY, name)
# in the current type system
typ = limit_type_depth(R, 0, true,
filter!(x->isa(x,TypeVar), Any[s.parameters...]))
return typ, isleaftype(s) && typeseq(typ, R)
return typ, isleaftype(s) && isa(R, Type) && typeof(R) === typeof(typ) && typeseq(R, typ)
end
end
end
Expand All @@ -502,14 +502,15 @@ function getfield_tfunc(s0::ANY, name)
elseif length(s.types) == 1 && isempty(s.parameters)
return s.types[1], true
else
R = reduce(tmerge, Bottom, map(unwrapva,s.types)) #=Union{s.types...}=#
R = reduce(tmerge, Bottom, map(unwrapva, s.types)) #=Union{s.types...}=#
alleq = isa(R, Type) && typeof(R) === typeof(s.types[1]) && typeseq(R, s.types[1])
# do the same limiting as the known-symbol case to preserve type-monotonicity
if isempty(s.parameters)
return R, typeseq(R, s.types[1])
return R, alleq
else
typ = limit_type_depth(R, 0, true,
filter!(x->isa(x,TypeVar), Any[s.parameters...]))
return typ, isleaftype(s) && typeseq(typ, R)
return typ, alleq && isleaftype(s) && typeof(R) === typeof(typ) && typeseq(R, typ)
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ let T = Array{Tuple{Vararg{Float64,TypeVar(:dim)}},1},
end
@test f16530a(:d) == Vector

let T1 = Tuple{Int, Float64},
T2 = Tuple{Int, Float32},
T = Tuple{T1, T2}

global f18037
f18037() = fieldtype(T, 1)
f18037(i) = fieldtype(T, i)

@test f18037() === T1
@test f18037(1) === T1
@test f18037(2) === T2

@test Base.return_types(f18037, ()) == Any[Type{T1}]
@test Base.return_types(f18037, (Int,)) == Any[Type{TypeVar(:T, Tuple{Int, AbstractFloat})}]
end

# issue #18015
type Triple18015
Expand Down

0 comments on commit 1869053

Please sign in to comment.