diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index b5e869ba7370a5..050d18fa1dc1bf 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -392,7 +392,7 @@ function typeof_tfunc(@nospecialize(t)) a = widenconst(typeof_tfunc(t.a)) b = widenconst(typeof_tfunc(t.b)) return Union{a, b} - elseif isa(t, TypeVar) && !(Any <: t.ub) + elseif isa(t, TypeVar) && !(Any === t.ub) return typeof_tfunc(t.ub) elseif isa(t, UnionAll) return rewrap_unionall(widenconst(typeof_tfunc(unwrap_unionall(t))), t) diff --git a/test/compiler/compiler.jl b/test/compiler/compiler.jl index 791c73a61f7dbf..b6d445a3516f46 100644 --- a/test/compiler/compiler.jl +++ b/test/compiler/compiler.jl @@ -1339,6 +1339,12 @@ let egal_tfunc @test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false) end +using Core.Compiler: typeof_tfunc +@test typeof_tfunc(Union{<:T, <:Real} where T<:Complex) == Union{Type{Complex{T}} where T<:Real, Type{<:Real}} + +f_typeof_tfunc(x) = typeof(x) +@test Base.return_types(f_typeof_tfunc, (Union{<:T, Int} where T<:Complex,)) == Any[Union{Type{Int}, Type{Complex{T}} where T<:Real}] + function f23024(::Type{T}, ::Int) where T 1 + 1 end