From 53b21f301effbf407ea7b3c73094d0113ba8d15a Mon Sep 17 00:00:00 2001 From: Simeon David Schaub Date: Thu, 10 Oct 2024 12:57:14 +0200 Subject: [PATCH 1/2] fix `Vararg{T,T} where T` crashing `code_typed` Not sure this is the right place to fix this error, perhaps `match.spec_types` should always be a tuple of valid types? fixes #55916 --- base/compiler/abstractinterpretation.jl | 8 +++++++- test/compiler/inference.jl | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index c8a25be422637..ba11f2cd954b8 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -547,7 +547,13 @@ function collect_slot_refinements(๐•ƒแตข::AbstractLattice, applicable::Vector{A sigt = Bottom for j = 1:length(applicable) match = applicable[j]::MethodMatch - sigt = sigt โŠ” fieldtype(match.spec_types, i) + spect = fieldtype(match.spec_types, i) + if isType(spect) + sigt = sigt โŠ” spect + else + sigt = Any + break + end end if sigt โŠ argt # i.e. signature type is strictly more specific than the type of the argument slot if slotrefinements === nothing diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 7c7726413004a..e3b1ac499e986 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -6048,3 +6048,10 @@ t255751 = Array{Float32, 3} issue55882_nfields(x::Union{T,Nothing}) where T<:Number = nfields(x) @test Base.infer_return_type(issue55882_nfields) <: Int + +# issue #55916 +f55916(x) = 1 +f55916(::Vararg{T,T}) where {T} = "2" +g55916(x) = f55916(x) +# this shouldn't error +@test only(code_typed(g55916, (Any,); optimize=false))[2] == Int From 4319fa9079e40051decfcba1065877b3d1195f99 Mon Sep 17 00:00:00 2001 From: Simeon David Schaub Date: Thu, 10 Oct 2024 16:38:19 +0200 Subject: [PATCH 2/2] address review comments Co-authored-by: Jameson Nash --- base/compiler/abstractinterpretation.jl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index ba11f2cd954b8..70623453e1666 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -547,13 +547,8 @@ function collect_slot_refinements(๐•ƒแตข::AbstractLattice, applicable::Vector{A sigt = Bottom for j = 1:length(applicable) match = applicable[j]::MethodMatch - spect = fieldtype(match.spec_types, i) - if isType(spect) - sigt = sigt โŠ” spect - else - sigt = Any - break - end + valid_as_lattice(match.spec_types, true) || continue + sigt = sigt โŠ” fieldtype(match.spec_types, i) end if sigt โŠ argt # i.e. signature type is strictly more specific than the type of the argument slot if slotrefinements === nothing