Skip to content

Commit

Permalink
fix #44705
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Mar 24, 2022
1 parent e0c5e96 commit 3ece96c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,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]
Expand All @@ -1554,6 +1558,8 @@ function tuple_tfunc(argtypes::Vector{Any})
else
params[i] = Type
end
elseif !isvarargtype(x) && x <: Type
params[i] = Type
else
params[i] = x
end
Expand Down
8 changes: 7 additions & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,12 @@ end
@test arraysize_tfunc(Vector, Float64) === Union{}
@test arraysize_tfunc(String, Int) === Union{}

# tuple_tfunc
# https://github.com/JuliaLang/julia/issues/44705
import Core.Compiler: tuple_tfunc, widenconst
@test widenconst(tuple_tfunc(Any[Type{Int}])) === Tuple{DataType}
@test tuple_tfunc(Any[Union{Type{Int32},Type{Int64}}]) === Tuple{Type}

function f23024(::Type{T}, ::Int) where T
1 + 1
end
Expand Down Expand Up @@ -2082,7 +2088,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
Expand Down

0 comments on commit 3ece96c

Please sign in to comment.