Skip to content

Commit

Permalink
inference: fix typeof-tfunc impl (#31405)
Browse files Browse the repository at this point in the history
(cherry picked from commit 604c9b2)
  • Loading branch information
vtjnash authored and KristofferC committed Apr 20, 2019
1 parent 3c1cc6c commit d48a928
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions test/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,26 @@ let egal_tfunc
@test egal_tfunc(Union{Int64, Float64}, AbstractArray) === Const(false)
end

using Core.Compiler: PartialStruct, nfields_tfunc, sizeof_tfunc, sizeof_nothrow
let PT = PartialStruct(Tuple{Int64,UInt64}, Any[Const(10, false), UInt64])
@test sizeof_tfunc(PT) === Const(16, false)
@test nfields_tfunc(PT) === Const(2, false)
@test sizeof_nothrow(PT) === true
end
@test sizeof_nothrow(Const(Tuple)) === false

using Core.Compiler: typeof_tfunc
@test typeof_tfunc(Tuple{Vararg{Int}}) == Type{Tuple{Vararg{Int,N}}} where N
@test typeof_tfunc(Tuple{Any}) == Type{<:Tuple{Any}}
@test typeof_tfunc(Type{Array}) === DataType
@test typeof_tfunc(Type{<:Array}) === DataType
@test typeof_tfunc(Array{Int}) == Type{Array{Int,N}} where N
@test typeof_tfunc(AbstractArray{Int}) == Type{<:AbstractArray{Int,N}} where N
@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
Expand Down

0 comments on commit d48a928

Please sign in to comment.