Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot flatten empty arrays #18852

Closed
CarloLucibello opened this issue Oct 9, 2016 · 4 comments
Closed

cannot flatten empty arrays #18852

CarloLucibello opened this issue Oct 9, 2016 · 4 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@CarloLucibello
Copy link
Contributor

CarloLucibello commented Oct 9, 2016

While empty array construction works well

julia> n=0;
julia> [u for u=1:n]
0-element Array{Int64,1}

and also the type is correctly inferred, I encountered this surprising error in a slightly more complex situation

julia> n=0;
julia> [(u,v) for u=1:n for v=1:10]
ERROR: ArgumentError: argument to Flatten must contain at least one iterator
 in start(::Base.Flatten{Base.Generator{UnitRange{Int64},##73#75}}) at ./iterator.jl:599
 in grow_to!(::Array{Tuple{Int64,Int64},1}, ::Base.Flatten{Base.Generator{UnitRange{Int64},##73#75}}) at ./array.jl:357
 in collect(::Base.Flatten{Base.Generator{UnitRange{Int64},##73#75}}) at ./array.jl:273
 in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
 in macro expansion at ./REPL.jl:95 [inlined]
 in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68

Here is the culprit line

d && throw(ArgumentError("argument to Flatten must contain at least one iterator"))

This one works well instead

julia> [(u,v) for u=1:10 for v=1:0]
0-element Array{Tuple{Int64,Int64},1}

Bye,
Carlo

@StefanKarpinski StefanKarpinski added this to the 0.5.x milestone Oct 11, 2016
@StefanKarpinski StefanKarpinski added the bug Indicates an unexpected problem or unintended behavior label Oct 11, 2016
@JeffBezanson
Copy link
Member

This is intentional, and would require something like #18823. In the meantime I can try some Nullable tricks and see if it performs ok.

@StefanKarpinski StefanKarpinski added help wanted Indicates that a maintainer wants help on an issue or pull request and removed help wanted Indicates that a maintainer wants help on an issue or pull request labels Oct 27, 2016
@akaysh
Copy link
Contributor

akaysh commented Dec 1, 2016

Hi, can I work on this issue if it is doable by a beginner?
Please help me with how and where to start. Thanks

@JeffBezanson
Copy link
Member

Hopefully will be fixed by #25261.

@JeffBezanson JeffBezanson modified the milestones: 0.5.x, 1.0.x Jan 15, 2018
@CarloLucibello
Copy link
Contributor Author

this is fixed on master

julia> n=0;

julia> [(u,v) for u=1:n for v=1:10]
0-element Array{Tuple{Int64,Int64},1}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants