From 7a79ed1e9f139d349c64d7a2bd88a462cdfe90fd Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 24 Aug 2021 20:50:27 -0400 Subject: [PATCH] fix a case where Vararg.T might be accessed when undefined (#41867) (cherry picked from commit 7a784de2bf4df9e931fa868b22231df9cdb01801) --- base/compiler/typelimits.jl | 2 +- test/compiler/inference.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index 3145517630958..23045c65cc6bb 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -130,7 +130,7 @@ function _limit_type_size(@nospecialize(t), @nospecialize(c), sources::SimpleVec elseif isa(t, DataType) if isa(c, Core.TypeofVararg) # Tuple{Vararg{T}} --> Tuple{T} is OK - return _limit_type_size(t, c.T, sources, depth, 0) + return _limit_type_size(t, unwrapva(c), sources, depth, 0) elseif isType(t) # allow taking typeof as Type{...}, but ensure it doesn't start nesting tt = unwrap_unionall(t.parameters[1]) (!isa(tt, DataType) || isType(tt)) && (depth += 1) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 4d7aed372f6c8..481fd84b87932 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -44,6 +44,11 @@ let t = Tuple{Ref{T},T,T} where T, c = Tuple{Ref, T, T} where T # #36407 @test t <: Core.Compiler.limit_type_size(t, c, Union{}, 1, 100) end +# obtain Vararg with 2 undefined fields +let va = ccall(:jl_type_intersection_with_env, Any, (Any, Any), Tuple{Tuple}, Tuple{Tuple{Vararg{Any, N}}} where N)[2][1] + @test Core.Compiler.limit_type_size(Tuple, va, Union{}, 2, 2) === Any +end + let # 40336 t = Type{Type{Int}} c = Type{Int}