Skip to content

Commit

Permalink
improve the effects of Base._tuple_unique_fieldtypes
Browse files Browse the repository at this point in the history
Discovered during inspecting #48097.
  • Loading branch information
aviatesk committed Jan 6, 2023
1 parent 463e5f0 commit 7803150
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,10 @@ function isvatuple(@nospecialize(t))
return false
end

unwrapva(t::Core.TypeofVararg) = isdefined(t, :T) ? t.T : Any
unwrapva(@nospecialize(t)) = t
function unwrapva(@nospecialize(t))
isa(t, Core.TypeofVararg) || return t
return isdefined(t, :T) ? t.T : Any
end

function unconstrain_vararg_length(va::Core.TypeofVararg)
# construct a new Vararg type where its length is unconstrained,
Expand Down
5 changes: 2 additions & 3 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,12 @@ function _tuple_unique_fieldtypes(@nospecialize t)
= unwrap_unionall(t)
# Given t = Tuple{Vararg{S}} where S<:Real, the various
# unwrapping/wrapping/va-handling here will return Real
if t isa Union
if t´ isa Union
union!(types, _tuple_unique_fieldtypes(rewrap_unionall(t´.a, t)))
union!(types, _tuple_unique_fieldtypes(rewrap_unionall(t´.b, t)))
else
r = Union{}
for ti in (t´::DataType).parameters
r = push!(types, rewrap_unionall(unwrapva(ti), t))
push!(types, rewrap_unionall(unwrapva(ti), t))
end
end
return Core.svec(types...)
Expand Down

0 comments on commit 7803150

Please sign in to comment.