From 582a2281e3fe0c3c609febd9f117db7766898f0f Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 4 Jan 2024 16:51:49 +0100 Subject: [PATCH] inference: Guard TypeVar special case against vararg (#52721) Fix #52613 by making the TypeVar special case in inference check for vararg first. There's nothing the special case can really do with vararg anyway, so fall back to the ordinary abstract call handling. --- base/compiler/abstractinterpretation.jl | 4 ++-- test/compiler/inference.jl | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 11d81dc3d0935..f252949661579 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2021,10 +2021,10 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f), elseif isa(f, Core.OpaqueClosure) # calling an OpaqueClosure about which we have no information returns no information return CallMeta(typeof(f).parameters[2], Effects(), NoCallInfo()) - elseif f === TypeVar + elseif f === TypeVar && !isvarargtype(argtypes[end]) # Manually look through the definition of TypeVar to # make sure to be able to get `PartialTypeVar`s out. - (la < 2 || la > 4) && return CallMeta(Bottom, EFFECTS_THROWS, NoCallInfo()) + 2 ≤ la ≤ 4 || return CallMeta(Bottom, EFFECTS_THROWS, NoCallInfo()) n = argtypes[2] ub_var = Const(Any) lb_var = Const(Union{}) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index cfd44967a5081..3d7a79bf815b0 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -5129,3 +5129,6 @@ let TV = TypeVar(:T) some = Some{Any}((TV, t)) @test abstract_call_unionall_vararg(some) isa UnionAll end + +# Issue #52613 +@test (code_typed((Any,)) do x; TypeVar(x...); end)[1][2] === TypeVar