Skip to content

Commit c7c1062

Browse files
committed
fix inference of Tuple{unknown}, where the parameter can be a Vararg
1 parent 5398799 commit c7c1062

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

base/inference.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,11 @@ function apply_type_tfunc(headtypetype::ANY, args::ANY...)
838838
#end
839839
uncertain = true
840840
if istuple
841-
push!(tparams, Any)
841+
if i == largs
842+
push!(tparams, Vararg)
843+
else
844+
push!(tparams, Any)
845+
end
842846
else
843847
# TODO: use rewrap_unionall to skip only the unknown parameters
844848
#push!(tparams, headtype.parameters[i-1])

test/inference.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,18 @@ function g19348(x)
466466
end
467467
test_inferred_static(@code_typed g19348((1, 2.0)))
468468

469+
# make sure Tuple{unknown} handles the possibility that `unknown` is a Vararg
470+
function maybe_vararg_tuple_1()
471+
x = Any[Vararg{Int}][1]
472+
Tuple{x}
473+
end
474+
@test Type{Tuple{Vararg{Int}}} <: Base.return_types(maybe_vararg_tuple_1, ())[1]
475+
function maybe_vararg_tuple_2()
476+
x = Type[Vararg{Int}][1]
477+
Tuple{x}
478+
end
479+
@test Type{Tuple{Vararg{Int}}} <: Base.return_types(maybe_vararg_tuple_2, ())[1]
480+
469481
# Issue 19641
470482
foo19641() = let a = 1.0
471483
Core.Inference.return_type(x -> x + a, Tuple{Float64})

0 commit comments

Comments
 (0)