From 9b7e90de8ec3ef6eb0ffe1f00b8e1bf94d6e45e6 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 23 Aug 2023 14:38:07 -0400 Subject: [PATCH] fix #50709, type bound error due to free typevar in inferred ccall ret type --- base/compiler/abstractinterpretation.jl | 6 ++++++ test/compiler/inference.jl | 3 +++ 2 files changed, 9 insertions(+) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 39fea90cbe993..566f51742bb50 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2186,6 +2186,12 @@ function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool) T = UnionAll(v, T) end end + if has_free_typevars(T) + fv = ccall(:jl_find_free_typevars, Vector{Any}, (Any,), T) + for v in fv + T = UnionAll(v, T) + end + end else T = rewrap_unionall(T, spsig) end diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index b04b7a40e2591..a710a85d0e99c 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -5142,6 +5142,9 @@ h45759(x::Tuple{Any,Vararg}; kwargs...) = x[1] + h45759(x[2:end]; kwargs...) h45759(x::Tuple{}; kwargs...) = 0 @test only(Base.return_types(h45759, Tuple{Tuple{Int,Int,Int,Int,Int,Int,Int}})) == Int +# issue #50709 +@test Base.code_typed_by_type(Tuple{Type{Vector{S}} where {T, S<:AbstractVector{T}}, UndefInitializer, Int})[1][2] == Vector{<:AbstractVector{T}} where T + @test only(Base.return_types((typeof([[[1]]]),)) do x sum(x) do v sum(length, v)