Skip to content

Commit

Permalink
Limit indexing to AbstractArray
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Sep 28, 2020
1 parent d1fae61 commit 91f4da0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ New library features

* The `redirect_*` functions can now be called on `IOContext` objects.
* New constructor `NamedTuple(iterator)` that constructs a named tuple from a key-value pair iterator.
* Generators support `getindex`, `firstindex`, and `lastindex` if indexing is supported by the underlying iterator ([#37648]).
* Generators support `getindex` when the underlying iterator is a subtype of `AbstractArray` ([#37648]).

Standard library changes
------------------------
Expand Down
2 changes: 0 additions & 2 deletions base/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ function getindex(g::Generator{<:AbstractArray}, I...)
end
end

getindex(g::Generator, I...) = collect(g)[I...]

firstindex(g::Generator) = firstindex(g.iter)
lastindex(g::Generator) = lastindex(g.iter)

Expand Down
2 changes: 1 addition & 1 deletion test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ end

@test (tuple(x) for x in ["a"])[1] == ("a",)
@test (tuple(x) for x in [[0]])[1] == ([0],)
@test (x * y for (x, y) in Dict(3 => 4))[1] == 12
@test_throws MethodError (x * y for (x, y) in Dict(3 => 4))[1]
end

0 comments on commit 91f4da0

Please sign in to comment.