Skip to content

Commit

Permalink
Make apply_type_nothrow robust against TypeVars in upper bounds (#…
Browse files Browse the repository at this point in the history
…49863)

For types like `Foo{S, T<:S}`, `apply_type_nothrow` could in some
situations check whether the argument is a subtype of the upper bound of
`T`, i.e. `S`, but subtyping agaist a plain `TypeVar` would fail.
Instead return `false` in this case.

Fixes #49785.
  • Loading branch information
martinholters committed May 19, 2023
1 parent c99d839 commit 1acec74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
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)
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
Expand Up @@ -4918,3 +4918,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

2 comments on commit 1acec74

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.