Skip to content

Commit

Permalink
Merge pull request JuliaLang#23602 from JuliaLang/jn/23413
Browse files Browse the repository at this point in the history
inference: leaftype Type{typeof(Union{})} is ambiguous
  • Loading branch information
JeffBezanson committed Sep 7, 2017
2 parents c5dff37 + d6c9902 commit 10af910
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 13 additions & 8 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,16 @@ const _Type_name = Type.body.name
isType(@nospecialize t) = isa(t, DataType) && (t::DataType).name === _Type_name

# true if Type is inlineable as constant (is a singleton)
isconstType(@nospecialize t) = isType(t) && (isleaftype(t.parameters[1]) || t.parameters[1] === Union{})
function isconstType(@nospecialize t)
isType(t) || return false
p1 = t.parameters[1]
# typeof(Bottom) is special since even though it is as leaftype,
# at runtime, it might be Type{Union{}} instead, so don't attempt inference of it
p1 === typeof(Union{}) && return false
p1 === Union{} && return true
isleaftype(p1) && return true
return false
end

iskindtype(@nospecialize t) = (t === DataType || t === UnionAll || t === Union || t === typeof(Bottom))

Expand Down Expand Up @@ -1147,13 +1156,9 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
rewrap(getfield_tfunc(s.b, name),s00))
elseif isa(s, Conditional)
return Bottom # Bool has no fields
elseif isa(s, Const) || isType(s)
elseif isa(s, Const) || isconstType(s)
if !isa(s, Const)
p1 = s.parameters[1]
if !isleaftype(p1)
return Any
end
sv = p1
sv = s.parameters[1]
else
sv = s.val
end
Expand Down Expand Up @@ -1189,7 +1194,7 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
end
s = typeof(sv)
end
if !isa(s,DataType) || s.abstract
if isType(s) || !isa(s, DataType) || s.abstract
return Any
end
if s <: Tuple && name Symbol
Expand Down
3 changes: 3 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,6 @@ g23024(TT::Tuple{DataType}) = f23024(TT[1], v23024)
@test Base.return_types(f23024, (DataType, Any)) == Any[Int]
@test Base.return_types(g23024, (Tuple{DataType},)) == Any[Int]
@test g23024((UInt8,)) === 2

@test !Core.Inference.isconstType(Type{typeof(Union{})}) # could be Core.TypeofBottom or Type{Union{}} at runtime
@test Base.return_types(supertype, (Type{typeof(Union{})},)) == Any[Any]

0 comments on commit 10af910

Please sign in to comment.