diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 9497bfa874e2af..d70c917404d94a 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -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)), getfield_tfunc(ti, 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) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 06aca0584a1a33..46a241785f19c9 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -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)