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 4, 2023
1 parent 52af407 commit 69f41e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 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
8 changes: 4 additions & 4 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ eltype(t::Type{<:Tuple}) = _compute_eltype(t)
function _tuple_unique_fieldtypes(@nospecialize t)
@_total_meta
types = IdSet()
= 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
union!(types, _tuple_unique_fieldtypes(rewrap_unionall(t´.a, t)))
union!(types, _tuple_unique_fieldtypes(rewrap_unionall(t´.b, t)))
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
= unwrap_unionall(t)::DataType
for ti in.parameters
r = push!(types, rewrap_unionall(unwrapva(ti), t))
end
end
Expand Down

0 comments on commit 69f41e1

Please sign in to comment.