Skip to content

Commit 5c5e255

Browse files
committed
Fix tmeet for vararg PartialStructs
1 parent 5d0a7dc commit 5c5e255

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

base/compiler/typelimits.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,19 @@ function tmeet(@nospecialize(v), @nospecialize(t))
561561
return Bottom
562562
end
563563
@assert widev <: Tuple
564-
new_fields = Vector{Any}(undef, length(v.fields))
564+
if !(ti <: Tuple)
565+
ti = widev
566+
end
567+
new_fields = Vector{Any}(undef, length(ti.parameters))
565568
for i = 1:length(new_fields)
566-
new_fields[i] = tmeet(v.fields[i], widenconst(getfield_tfunc(t, Const(i))))
569+
new_fields[i] = tmeet(getfield_tfunc(v, Const(i)), widenconst(getfield_tfunc(t, Const(i))))
567570
if new_fields[i] === Bottom
568571
return Bottom
569572
end
570573
end
574+
if isvatuple(ti)
575+
new_fields[end] = Vararg{new_fields[end]}
576+
end
571577
return tuple_tfunc(new_fields)
572578
elseif isa(v, Conditional)
573579
if !(Bool <: t)

test/compiler/inference.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,3 +2980,13 @@ f38888() = S38888(Base.inferencebarrier(3))
29802980
@test f38888() isa S38888
29812981
g38888() = S38888(Base.inferencebarrier(3), nothing)
29822982
@test g38888() isa S38888
2983+
2984+
# issue #38971
2985+
f28971() = (1, [2,3]...)::Tuple{Int,Int,Int}
2986+
@test @inferred(f28971()) == (1, 2, 3)
2987+
g28971_1() = (1, [2,3]...)::Tuple{Vararg{Int}}
2988+
@test @inferred(Tuple{Int, Vararg{Int}}, g28971_1()) == (1, 2, 3)
2989+
g28971_2() = (1, [2,3]...)::Tuple{Int, Vararg{Int}}
2990+
@test @inferred(Tuple{Int, Vararg{Int}}, g28971_2()) == (1, 2, 3)
2991+
g28971_3() = (1, [2,3]...)::Tuple{Int, Int, Vararg{Int}}
2992+
@test @inferred(Tuple{Int, Int, Vararg{Int}}, g28971_3()) == (1, 2, 3)

0 commit comments

Comments
 (0)