Skip to content

Commit

Permalink
Allow Iterators.flatten for empty tuple (JuliaLang#29112)
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC authored and JeffBezanson committed Sep 12, 2018
1 parent 62de472 commit b4c370d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ IteratorEltype(::Type) = HasEltype() # HasEltype is the default
IteratorEltype(::Type{Generator{I,T}}) where {I,T} = EltypeUnknown()

IteratorEltype(::Type{Any}) = EltypeUnknown()
IteratorEltype(::Type{Union{}}) = EltypeUnknown()
1 change: 1 addition & 0 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ _flatteneltype(I, et) = EltypeUnknown()
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:NTuple{N,Any}}) where {N} = HasLength()
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:Tuple}) = SizeUnknown()
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{<:Number}) = HasLength()
flatten_iteratorsize(::Union{HasShape, HasLength}, ::Type{Union{}}) = SizeUnknown()
flatten_iteratorsize(a, b) = SizeUnknown()

_flatten_iteratorsize(sz, ::EltypeUnknown, I) = SizeUnknown()
Expand Down
1 change: 1 addition & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ end
@test length(flatten(zip(1:3, 4:6))) == 6
@test length(flatten(1:6)) == 6
@test collect(flatten(Any[])) == Any[]
@test collect(flatten(())) == Union{}[]
@test_throws ArgumentError length(flatten(NTuple[(1,), ()])) # #16680
@test_throws ArgumentError length(flatten([[1], [1]]))

Expand Down

0 comments on commit b4c370d

Please sign in to comment.