Skip to content

Commit 02cdde9

Browse files
committed
Fix typeassert_tfunc for vararg PartialStructs
1 parent 8240225 commit 02cdde9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

base/compiler/tfuncs.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,17 +555,22 @@ function typeassert_type_instance(@nospecialize(v), @nospecialize(t))
555555
widev = widenconst(v)
556556
if widev <: t
557557
return v
558-
elseif typeintersect(widev, t) === Bottom
558+
end
559+
tr = typeintersect(widev, t)
560+
if tr === Bottom
559561
return Bottom
560562
end
561-
@assert widev <: Tuple
562-
new_fields = Vector{Any}(undef, length(v.fields))
563+
@assert tr <: Tuple
564+
new_fields = Vector{Any}(undef, length(tr.parameters))
563565
for i = 1:length(new_fields)
564-
new_fields[i] = typeassert_type_instance(v.fields[i], getfield_tfunc(t, Const(i)))
566+
new_fields[i] = typeassert_type_instance(getfield_tfunc(v, Const(i)), getfield_tfunc(tr, Const(i)))
565567
if new_fields[i] === Bottom
566568
return Bottom
567569
end
568570
end
571+
if isvatuple(tr)
572+
new_fields[end] = Vararg{new_fields[end]}
573+
end
569574
return tuple_tfunc(new_fields)
570575
elseif isa(v, Conditional)
571576
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)