From 046be325bbe2af9eff3475f3117db55e35545720 Mon Sep 17 00:00:00 2001
From: Klaus Crusius <klaus.crusius@web.de>
Date: Mon, 10 Sep 2018 13:02:35 +0200
Subject: [PATCH 1/3] allow Iterators.flatten for empty tuple

---
 base/iterators.jl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/base/iterators.jl b/base/iterators.jl
index 1564ffa1be9a1..2cddb7b759afc 100644
--- a/base/iterators.jl
+++ b/base/iterators.jl
@@ -873,6 +873,7 @@ julia> collect(Iterators.flatten((1:2, 8:9)))
 flatten(itr) = Flatten(itr)
 
 eltype(::Type{Flatten{I}}) where {I} = eltype(eltype(I))
+IteratorEltype(::Type{Union{}}) = EltypeUnknown()
 IteratorEltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, IteratorEltype(I))
 _flatteneltype(I, ::HasEltype) = IteratorEltype(eltype(I))
 _flatteneltype(I, et) = EltypeUnknown()
@@ -880,6 +881,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()

From 61f125656baba27d788e9b8f07ad25ead6e2577e Mon Sep 17 00:00:00 2001
From: Klaus Crusius <klaus.crusius@web.de>
Date: Mon, 10 Sep 2018 21:28:15 +0200
Subject: [PATCH 2/3] added testcase for `Iterators.flatten(())`

---
 test/iterators.jl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/iterators.jl b/test/iterators.jl
index 5fca4f11b91ad..6e5f88a72cd0d 100644
--- a/test/iterators.jl
+++ b/test/iterators.jl
@@ -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]]))
 

From fcbea5f825356937340b7fabca9fb56545aa2a90 Mon Sep 17 00:00:00 2001
From: Klaus Crusius <klaus.crusius@web.de>
Date: Tue, 11 Sep 2018 07:57:50 +0200
Subject: [PATCH 3/3] moved method of `IteratorEltype` to `generator.jl`

---
 base/generator.jl | 1 +
 base/iterators.jl | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/base/generator.jl b/base/generator.jl
index b0f7e32d0b22f..73d0e8a2e3ee2 100644
--- a/base/generator.jl
+++ b/base/generator.jl
@@ -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()
diff --git a/base/iterators.jl b/base/iterators.jl
index 2cddb7b759afc..ac3c3ad88d9a3 100644
--- a/base/iterators.jl
+++ b/base/iterators.jl
@@ -873,7 +873,6 @@ julia> collect(Iterators.flatten((1:2, 8:9)))
 flatten(itr) = Flatten(itr)
 
 eltype(::Type{Flatten{I}}) where {I} = eltype(eltype(I))
-IteratorEltype(::Type{Union{}}) = EltypeUnknown()
 IteratorEltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, IteratorEltype(I))
 _flatteneltype(I, ::HasEltype) = IteratorEltype(eltype(I))
 _flatteneltype(I, et) = EltypeUnknown()