Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ function _compute_eltype(@nospecialize t)
end
end

# We'd like to be able to infer eltype(::Tuple), which needs to be able to
# look at these four methods:
#
# julia> methods(Base.eltype, Tuple{Type{<:Tuple}})
# 4 methods for generic function "eltype" from Base:
# [1] eltype(::Type{Union{}})
# @ abstractarray.jl:234
# [2] eltype(::Type{Tuple{}})
# @ tuple.jl:199
# [3] eltype(t::Type{<:Tuple{Vararg{E}}}) where E
# @ tuple.jl:200
# [4] eltype(t::Type{<:Tuple})
# @ tuple.jl:209
typeof(function eltype end).name.max_methods = UInt8(4)

# version of tail that doesn't throw on empty tuples (used in array indexing)
safe_tail(t::Tuple) = tail(t)
safe_tail(t::Tuple{}) = ()
Expand Down
1 change: 1 addition & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,4 @@ namedtup = (;a=1, b=2, c=3)

# Make sure that tuple iteration is foldable
@test Core.Compiler.is_foldable(Base.infer_effects(iterate, Tuple{NTuple{4, Float64}, Int}))
@test Core.Compiler.is_foldable(Base.infer_effects(eltype, Tuple{Tuple}))