Skip to content

Commit

Permalink
fix #32465, inference of splatting unionall NamedTuple types (#32494)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2350c04)
  • Loading branch information
JeffBezanson authored and KristofferC committed Jul 8, 2019
1 parent b92c6ed commit bd9f411
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,13 @@ function precise_container_type(@nospecialize(typ), vtypes::VarTable, sv::Infere
tti0 = widenconst(typ)
tti = unwrap_unionall(tti0)
if isa(tti, DataType) && tti.name === NamedTuple_typename
tti0 = tti.parameters[2]
while isa(tti0, TypeVar)
tti0 = tti0.ub
# A NamedTuple iteration is the the same as the iteration of its Tuple parameter:
# compute a new `tti == unwrap_unionall(tti0)` based on that Tuple type
tti = tti.parameters[2]
while isa(tti, TypeVar)
tti = tti.ub
end
tti0 = rewrap_unionall(tti, tti0)
end
if isa(tti, Union)
utis = uniontypes(tti)
Expand Down
6 changes: 6 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,12 @@ Base.iterate(::Iterator27434, ::Any) = nothing
@test @inferred((1, 2, 3) == (1, 2, 3))
@test Core.Compiler.return_type(splat27434, Tuple{typeof(Iterators.repeated(1))}) == Union{}

# issue #32465
let rt = Base.return_types(splat27434, (NamedTuple{(:x,), Tuple{T}} where T,))
@test rt == Any[Tuple{Any}]
@test !Base.has_free_typevars(rt[1])
end

# issue #27078
f27078(T::Type{S}) where {S} = isa(T, UnionAll) ? f27078(T.body) : T
T27078 = Vector{Vector{T}} where T
Expand Down

0 comments on commit bd9f411

Please sign in to comment.