Skip to content

Commit 7a784de

Browse files
authored
fix a case where Vararg.T might be accessed when undefined (#41867)
1 parent 47c5d62 commit 7a784de

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/compiler/typelimits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function _limit_type_size(@nospecialize(t), @nospecialize(c), sources::SimpleVec
130130
elseif isa(t, DataType)
131131
if isa(c, Core.TypeofVararg)
132132
# Tuple{Vararg{T}} --> Tuple{T} is OK
133-
return _limit_type_size(t, c.T, sources, depth, 0)
133+
return _limit_type_size(t, unwrapva(c), sources, depth, 0)
134134
elseif isType(t) # allow taking typeof as Type{...}, but ensure it doesn't start nesting
135135
tt = unwrap_unionall(t.parameters[1])
136136
(!isa(tt, DataType) || isType(tt)) && (depth += 1)

test/compiler/inference.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ let t = Tuple{Ref{T},T,T} where T, c = Tuple{Ref, T, T} where T # #36407
4444
@test t <: Core.Compiler.limit_type_size(t, c, Union{}, 1, 100)
4545
end
4646

47+
# obtain Vararg with 2 undefined fields
48+
let va = ccall(:jl_type_intersection_with_env, Any, (Any, Any), Tuple{Tuple}, Tuple{Tuple{Vararg{Any, N}}} where N)[2][1]
49+
@test Core.Compiler.limit_type_size(Tuple, va, Union{}, 2, 2) === Any
50+
end
51+
4752
let # 40336
4853
t = Type{Type{Int}}
4954
c = Type{Int}

0 commit comments

Comments
 (0)