Skip to content

Commit

Permalink
Fix tmeet for vararg PartialStructs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Jan 26, 2021
1 parent 5d0a7dc commit 5c5e255
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,19 @@ function tmeet(@nospecialize(v), @nospecialize(t))
return Bottom
end
@assert widev <: Tuple
new_fields = Vector{Any}(undef, length(v.fields))
if !(ti <: Tuple)
ti = widev
end
new_fields = Vector{Any}(undef, length(ti.parameters))
for i = 1:length(new_fields)
new_fields[i] = tmeet(v.fields[i], widenconst(getfield_tfunc(t, Const(i))))
new_fields[i] = tmeet(getfield_tfunc(v, Const(i)), widenconst(getfield_tfunc(t, Const(i))))
if new_fields[i] === Bottom
return Bottom
end
end
if isvatuple(ti)
new_fields[end] = Vararg{new_fields[end]}
end
return tuple_tfunc(new_fields)
elseif isa(v, Conditional)
if !(Bool <: t)
Expand Down
10 changes: 10 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2980,3 +2980,13 @@ f38888() = S38888(Base.inferencebarrier(3))
@test f38888() isa S38888
g38888() = S38888(Base.inferencebarrier(3), nothing)
@test g38888() isa S38888

# issue #38971
f28971() = (1, [2,3]...)::Tuple{Int,Int,Int}
@test @inferred(f28971()) == (1, 2, 3)
g28971_1() = (1, [2,3]...)::Tuple{Vararg{Int}}
@test @inferred(Tuple{Int, Vararg{Int}}, g28971_1()) == (1, 2, 3)
g28971_2() = (1, [2,3]...)::Tuple{Int, Vararg{Int}}
@test @inferred(Tuple{Int, Vararg{Int}}, g28971_2()) == (1, 2, 3)
g28971_3() = (1, [2,3]...)::Tuple{Int, Int, Vararg{Int}}
@test @inferred(Tuple{Int, Int, Vararg{Int}}, g28971_3()) == (1, 2, 3)

0 comments on commit 5c5e255

Please sign in to comment.