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

Tuples can be indexed multidimensionally... kind of #20453

Closed
ararslan opened this issue Feb 4, 2017 · 1 comment
Closed

Tuples can be indexed multidimensionally... kind of #20453

ararslan opened this issue Feb 4, 2017 · 1 comment
Labels
collections Data structures holding multiple items, e.g. sets

Comments

@ararslan
Copy link
Member

ararslan commented Feb 4, 2017

Take a tuple, any old tuple, say (1,). Now try to getindex it with as many indices as you'd like.

julia> (1,)[]  # 0 indices
ERROR: StackOverflowError:
Stacktrace:
 [1] getindex(::Tuple{Int64}) at ./multidimensional.jl:0
 [2] getindex(::Tuple{Int64}) at ./multidimensional.jl:387 (repeats 79999 times)

julia> (1,)[1]  # 1 index
1

julia> (1,)[1,1]  # 2 indices
ERROR: StackOverflowError:
Stacktrace:
 [1] getindex(::Tuple{Int64}, ::Int64, ::Int64) at ./multidimensional.jl:0
 [2] getindex(::Tuple{Int64}, ::Int64, ::Int64) at ./multidimensional.jl:387 (repeats 79999 times)

The offending definition is here, reproduced below:

getindex(t::Tuple, I...) = getindex(t, IteratorsMD.flatten(I)...)

It's pretty clear that this method will recurse infinitely since the only more specific getindex method for tuples is getindex(::Tuple, ::Integer).

Tuples aren't really multidimensional objects, so it'd probably be best to stick with the one method.

@ararslan ararslan added the collections Data structures holding multiple items, e.g. sets label Feb 4, 2017
@StefanKarpinski
Copy link
Member

Removing non-linear indexing of tuples seems like a no-brainer to me, especially since it's currently too broken for it to actually be used anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets
Projects
None yet
Development

No branches or pull requests

2 participants