Skip to content

Commit c76690e

Browse files
JeffBezansonKristofferC
authored andcommitted
improve instanceof_tfunc to take declared parameter bounds into account (#33472)
(cherry picked from commit 7466d11)
1 parent b5ccd0f commit c76690e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/compiler/tfuncs.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ function instanceof_tfunc(@nospecialize(t))
7878
elseif isa(t, UnionAll)
7979
t′ = unwrap_unionall(t)
8080
t′′, isexact = instanceof_tfunc(t′)
81-
return rewrap_unionall(t′′, t), isexact
81+
tr = rewrap_unionall(t′′, t)
82+
if t′′ isa DataType && !has_free_typevars(tr)
83+
# a real instance must be within the declared bounds of the type,
84+
# so we can intersect with the original wrapper.
85+
tr = typeintersect(tr, t′′.name.wrapper)
86+
end
87+
return tr, isexact
8288
elseif isa(t, Union)
8389
ta, isexact_a = instanceof_tfunc(t.a)
8490
tb, isexact_b = instanceof_tfunc(t.b)

test/compiler/inference.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,3 +2442,6 @@ f31974(n::Int) = f31974(1:n)
24422442
# This query hangs if type inference improperly attempts to const prop
24432443
# call cycles.
24442444
@test code_typed(f31974, Tuple{Int}) !== nothing
2445+
2446+
f_overly_abstract_complex() = Complex(Ref{Number}(1)[])
2447+
@test Base.return_types(f_overly_abstract_complex, Tuple{}) == [Complex]

0 commit comments

Comments
 (0)