Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make apply_type_nothrow robust against TypeVars in upper bounds #49863

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ function apply_type_nothrow(𝕃::AbstractLattice, argtypes::Vector{Any}, @nospe
end
else
istype || return false
if !(T <: u.var.ub)
if isa(u.var.ub, TypeVar) || !(T <: u.var.ub)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also do has_free_typevars(u.var.ub) to cover some other (even more rare) cases

return false
end
if exact ? !(u.var.lb <: T) : !(u.var.lb === Bottom)
Expand Down
14 changes: 14 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4904,3 +4904,17 @@ let src = code_typed1((Bool,Base.RefValue{String}, Base.RefValue{Any},Int,)) do
end
@test count(@nospecialize(x)->isa(x, Core.PhiNode), src.code) == 0
end

struct Issue49785{S, T<:S} end
let 𝕃 = Core.Compiler.OptimizerLattice()
argtypes = Any[Core.Compiler.Const(Issue49785),
Union{Type{String},Type{Int}},
Union{Type{String},Type{Int}}]
rt = Type{Issue49785{<:Any, Int}}
# the following should not throw
@test !Core.Compiler.apply_type_nothrow(𝕃, argtypes, rt)
@test code_typed() do
S = Union{Type{String},Type{Int}}[Int][1]
map(T -> Issue49785{S,T}, (a = S,))
end isa Vector
end