Skip to content

Commit d48a928

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

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

base/compiler/tfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ function typeof_tfunc(@nospecialize(t))
392392
a = widenconst(typeof_tfunc(t.a))
393393
b = widenconst(typeof_tfunc(t.b))
394394
return Union{a, b}
395-
elseif isa(t, TypeVar) && !(Any <: t.ub)
395+
elseif isa(t, TypeVar) && !(Any === t.ub)
396396
return typeof_tfunc(t.ub)
397397
elseif isa(t, UnionAll)
398398
return rewrap_unionall(widenconst(typeof_tfunc(unwrap_unionall(t))), t)

test/compiler/compiler.jl

+20
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,26 @@ let egal_tfunc
13391339
@test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false)
13401340
end
13411341

1342+
using Core.Compiler: PartialStruct, nfields_tfunc, sizeof_tfunc, sizeof_nothrow
1343+
let PT = PartialStruct(Tuple{Int64,UInt64}, Any[Const(10, false), UInt64])
1344+
@test sizeof_tfunc(PT) === Const(16, false)
1345+
@test nfields_tfunc(PT) === Const(2, false)
1346+
@test sizeof_nothrow(PT) === true
1347+
end
1348+
@test sizeof_nothrow(Const(Tuple)) === false
1349+
1350+
using Core.Compiler: typeof_tfunc
1351+
@test typeof_tfunc(Tuple{Vararg{Int}}) == Type{Tuple{Vararg{Int,N}}} where N
1352+
@test typeof_tfunc(Tuple{Any}) == Type{<:Tuple{Any}}
1353+
@test typeof_tfunc(Type{Array}) === DataType
1354+
@test typeof_tfunc(Type{<:Array}) === DataType
1355+
@test typeof_tfunc(Array{Int}) == Type{Array{Int,N}} where N
1356+
@test typeof_tfunc(AbstractArray{Int}) == Type{<:AbstractArray{Int,N}} where N
1357+
@test typeof_tfunc(Union{<:T, <:Real} where T<:Complex) == Union{Type{Complex{T}} where T<:Real, Type{<:Real}}
1358+
1359+
f_typeof_tfunc(x) = typeof(x)
1360+
@test Base.return_types(f_typeof_tfunc, (Union{<:T, Int} where T<:Complex,)) == Any[Union{Type{Int}, Type{Complex{T}} where T<:Real}]
1361+
13421362
function f23024(::Type{T}, ::Int) where T
13431363
1 + 1
13441364
end

0 commit comments

Comments
 (0)