Skip to content

Commit adc798a

Browse files
vtjnashKristofferC
authored andcommitted
inference: fix typeof-tfunc impl (#31405)
(cherry picked from commit 604c9b2)
1 parent 0bc6c5d commit adc798a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

base/compiler/tfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function typeof_tfunc(@nospecialize(t))
441441
a = widenconst(typeof_tfunc(t.a))
442442
b = widenconst(typeof_tfunc(t.b))
443443
return Union{a, b}
444-
elseif isa(t, TypeVar) && !(Any <: t.ub)
444+
elseif isa(t, TypeVar) && !(Any === t.ub)
445445
return typeof_tfunc(t.ub)
446446
elseif isa(t, UnionAll)
447447
return rewrap_unionall(widenconst(typeof_tfunc(unwrap_unionall(t))), t)

test/compiler/inference.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,12 @@ let egal_tfunc
13401340
@test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false)
13411341
end
13421342

1343+
using Core.Compiler: typeof_tfunc
1344+
@test typeof_tfunc(Union{<:T, <:Real} where T<:Complex) == Union{Type{Complex{T}} where T<:Real, Type{<:Real}}
1345+
1346+
f_typeof_tfunc(x) = typeof(x)
1347+
@test Base.return_types(f_typeof_tfunc, (Union{<:T, Int} where T<:Complex,)) == Any[Union{Type{Int}, Type{Complex{T}} where T<:Real}]
1348+
13431349
function f23024(::Type{T}, ::Int) where T
13441350
1 + 1
13451351
end

0 commit comments

Comments
 (0)