Skip to content

Commit a3e2316

Browse files
authored
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.
1 parent 479743e commit a3e2316

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,12 @@ function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
21572157
T = UnionAll(v, T)
21582158
end
21592159
end
2160+
if has_free_typevars(T)
2161+
fv = ccall(:jl_find_free_typevars, Vector{Any}, (Any,), T)
2162+
for v in fv
2163+
T = UnionAll(v, T)
2164+
end
2165+
end
21602166
else
21612167
T = rewrap_unionall(T, spsig)
21622168
end

test/compiler/inference.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5142,6 +5142,9 @@ h45759(x::Tuple{Any,Vararg}; kwargs...) = x[1] + h45759(x[2:end]; kwargs...)
51425142
h45759(x::Tuple{}; kwargs...) = 0
51435143
@test only(Base.return_types(h45759, Tuple{Tuple{Int,Int,Int,Int,Int,Int,Int}})) == Int
51445144

5145+
# issue #50709
5146+
@test Base.code_typed_by_type(Tuple{Type{Vector{S}} where {T, S<:AbstractVector{T}}, UndefInitializer, Int})[1][2] == Vector{<:AbstractVector{T}} where T
5147+
51455148
@test only(Base.return_types((typeof([[[1]]]),)) do x
51465149
sum(x) do v
51475150
sum(length, v)

0 commit comments

Comments
 (0)