Skip to content

Commit f3e9556

Browse files
authored
fix isknownlength for new Vararg representation (#39407)
1 parent 27eee41 commit f3e9556

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/compiler/typeutils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ argtypes_to_type(argtypes::Array{Any,1}) = Tuple{anymap(widenconst, argtypes)...
4949

5050
function isknownlength(t::DataType)
5151
isvatuple(t) || return true
52-
return length(t.parameters) > 0 && isa(unwrap_unionall(t.parameters[end]).parameters[2], Int)
52+
va = t.parameters[end]
53+
return isdefined(va, :N) && va.N isa Int
5354
end
5455

5556
# test if non-Type, non-TypeVar `x` can be used to parameterize a type

test/compiler/inference.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,3 +3013,11 @@ f_aggressive(x) = g_aggressive(x, 1)
30133013
# render the annotation effectless.
30143014
@test Base.return_types(f_nonaggressive, Tuple{Int})[1] == Val
30153015
@test Base.return_types(f_aggressive, Tuple{Int})[1] == Val{1}
3016+
3017+
function splat_lotta_unions()
3018+
a = Union{Tuple{Int},Tuple{String,Vararg{Int}},Tuple{Int,Vararg{Int}}}[(2,)][1]
3019+
b = Union{Int8,Int16,Int32,Int64,Int128}[1][1]
3020+
c = Union{Int8,Int16,Int32,Int64,Int128}[1][1]
3021+
(a...,b...,c...)
3022+
end
3023+
@test Core.Compiler.return_type(splat_lotta_unions, Tuple{}) >: Tuple{Int,Int,Int}

0 commit comments

Comments
 (0)