Skip to content

Commit

Permalink
inference: type bound error due to free typevar in sparam env (#51013)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JeffBezanson authored Aug 31, 2023
1 parent 479743e commit a3e2316
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,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
Expand Down
3 changes: 3 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a3e2316

Please sign in to comment.