From 763ec695a746102c8ebc6c0575af02aa1db3e43f Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 31 Aug 2023 14:57:50 -0400 Subject: [PATCH] inference: type bound error due to free typevar in sparam env (#51013) Fix #50709 This issue *appears* fixed on master due to #50432, which simply removed the error. This fixes the underlying cause, which is that we sometimes return typevars in the environment from intersection that have free vars in their bounds. I think it's reasonable to just widen these aggressively, since we usually cannot do much with these kinds of unknown static parameters anyway. (cherry picked from commit a3e23161b60e51d7aaa1183559dc70b9c28426e6) --- 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 48b6a234d13ba..973c7dc6f879b 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -2182,6 +2182,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 1799dd94de74f..8b980f1fdb17c 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -5086,6 +5086,9 @@ let x = Issue50544((1, Issue50544((2.0, 'x')))) @test only(Base.return_types(h_issue50544, (typeof(x),))) == Type{Issue50544{Tuple{Int,Float64}}} end +# 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 + # override const-prop' return type with the concrete-eval result # if concrete-eval returns non-inlineable constant Base.@assume_effects :foldable function continue_const_prop(i, j)