diff --git a/NEWS.md b/NEWS.md index 6bf2515948ad9..f1a4fdb484468 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ------------------------ diff --git a/base/generator.jl b/base/generator.jl index 8d887b3964182..5d50124492928 100644 --- a/base/generator.jl +++ b/base/generator.jl @@ -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) diff --git a/test/functional.jl b/test/functional.jl index 2fb9f0668eccc..adf83af83b6c6 100644 --- a/test/functional.jl +++ b/test/functional.jl @@ -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