From adc798aa8b4668087681451c2d86c809d682f5df Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 21 Mar 2019 17:19:21 -0400 Subject: [PATCH] inference: fix typeof-tfunc impl (#31405) (cherry picked from commit 604c9b26742decd4ce373b4dc0be36c4b0e5c632) --- base/compiler/tfuncs.jl | 2 +- test/compiler/inference.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index e7fc99d0fdf4af..e9a227a9040c8e 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -441,7 +441,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/inference.jl b/test/compiler/inference.jl index a06f1b19601de3..632fe50cf1d2b6 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -1340,6 +1340,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