Skip to content

Commit

Permalink
fix #31803, covariance handling in fieldtype_tfunc (#31848)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Apr 28, 2019
1 parent dc6c7c7 commit a78f895
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
t = Bottom
for i in 1:length(ftypes)
ft1 = unwrapva(ftypes[i])
exactft1 = exact || !has_free_typevars(ft1)
exactft1 = exact || (!has_free_typevars(ft1) && u.name !== Tuple.name)
ft1 = rewrap_unionall(ft1, s)
if exactft1
if issingletontype(ft1)
Expand Down Expand Up @@ -939,7 +939,7 @@ function _fieldtype_tfunc(@nospecialize(s), exact::Bool, @nospecialize(name))
ft = ftypes[fld]
end

exactft = exact || !has_free_typevars(ft)
exactft = exact || (!has_free_typevars(ft) && u.name !== Tuple.name)
ft = rewrap_unionall(ft, s)
if exactft
if issingletontype(ft)
Expand Down
2 changes: 2 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ let fieldtype_tfunc = Core.Compiler.fieldtype_tfunc,
@test fieldtype_tfunc(Union{Type{Base.RefValue{<:Real}}, Type{Int32}}, Const(:x)) == Const(Real)
@test fieldtype_tfunc(Const(Union{Base.RefValue{<:Real}, Type{Int32}}), Const(:x)) == Type
@test fieldtype_tfunc(Type{Union{Base.RefValue{T}, Type{Int32}}} where {T<:Real}, Const(:x)) == Type
@test fieldtype_tfunc(Type{<:Tuple}, Const(1)) == Type
@test fieldtype_tfunc(Type{<:Tuple}, Any) == Type
@test fieldtype_nothrow(Type{Base.RefValue{<:Real}}, Const(:x))
@test !fieldtype_nothrow(Type{Union{}}, Const(:x))
@test !fieldtype_nothrow(Union{Type{Base.RefValue{T}}, Int32} where {T<:Real}, Const(:x))
Expand Down

0 comments on commit a78f895

Please sign in to comment.