diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index 23a18ae8d8aeb..c07f0a5c2f0b3 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -1515,6 +1515,10 @@ function tuple_tfunc(argtypes::Vector{Any}) params[i] = typeof(x.val) else x = isvarargtype(x) ? x : widenconst(x) + # since there don't exist any values whose runtime type are `Tuple{Type{...}}`, + # here we should turn such `Type{...}`-parameters to valid parameters, e.g. + # (::Type{Int},) -> Tuple{DataType} (or PartialStruct for more accuracy) + # (::Union{Type{Int32},Type{Int64}}) -> Tuple{Type} if isType(x) anyinfo = true xparam = x.parameters[1] @@ -1523,6 +1527,8 @@ function tuple_tfunc(argtypes::Vector{Any}) else params[i] = Type end + elseif !isvarargtype(x) && hasintersect(x, Type) + params[i] = Union{x, Type} else params[i] = x end diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 7f7b14b1705c1..38eecece6f504 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -1564,6 +1564,15 @@ end @test arraysize_tfunc(Vector, Float64) === Union{} @test arraysize_tfunc(String, Int) === Union{} +let tuple_tfunc + function tuple_tfunc(@nospecialize xs...) + return Core.Compiler.tuple_tfunc(Any[xs...]) + end + @test Core.Compiler.widenconst(tuple_tfunc(Type{Int})) === Tuple{DataType} + # https://github.com/JuliaLang/julia/issues/44705 + @test tuple_tfunc(Union{Type{Int32},Type{Int64}}) === Tuple{Type} +end + function f23024(::Type{T}, ::Int) where T 1 + 1 end @@ -2084,7 +2093,7 @@ let M = Module() obj = $(Expr(:new, M.BePartialStruct, 42, :cond)) r1 = getfield(obj, :cond) ? 0 : a # r1::Union{Nothing,Int}, not r1::Int (because PartialStruct doesn't wrap Conditional) a = $(gensym(:anyvar))::Any - r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing) (we don't need to worry about constrait invalidation here) + r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing) (we don't need to worry about constraint invalidation here) return r1, r2 # ::Tuple{Union{Nothing,Int},Any} end |> only end