Skip to content

Problematic interaction between Stateful and map #42168

Closed

Description

When trying the following code:

v = split("abcd", "")
it = Iterators.Stateful(Iterators.map(identity, v))
popfirst!(it)
popfirst!(it)
collect(Iterators.take(it, 2))

in Julia 1.6.2 and 1.7.0-beta4:

signal (11): Segmentation fault
in expression starting at none:0
jl_gc_pool_alloc at /buildworker/worker/package_linux64/build/src/gc.c:1211
jl_gc_alloc_ at /buildworker/worker/package_linux64/build/src/julia_internal.h:336 [inlined]
jl_gc_alloc at /buildworker/worker/package_linux64/build/src/gc.c:3278
jl_gc_alloc_buf at /buildworker/worker/package_linux64/build/src/julia_internal.h:370 [inlined]
[...]

whereas in Julia 1.8.0-DEV.486 a simple error (still not the right answer):

ERROR: BoundsError: attempt to access 1-element Vector{SubString{String}} at index [2]
Stacktrace:
 [1] setindex!
   @ ./array.jl:946 [inlined]
 [2] collect_to!
   @ ./array.jl:829 [inlined]
 [3] collect_to_with_first!
   @ ./array.jl:803 [inlined]
 [4] _collect(c::UnitRange{Int64}, itr::Base.Iterators.Take{Base.Iterators.Stateful{Base.Generator{Vector{SubString{String}}, typeof(identity)}, Union{Nothing, Tuple{SubString{String}, Int64}}}}, #unused#::Base.EltypeUnknown, isz::Base.HasLength)
   @ Base ./array.jl:797
 [5] collect(itr::Base.Iterators.Take{Base.Iterators.Stateful{Base.Generator{Vector{SubString{String}}, typeof(identity)}, Union{Nothing, Tuple{SubString{String}, Int64}}}})
   @ Base ./array.jl:694
 [6] top-level scope
   @ REPL[4]:1

Might be related to #35530 and #41919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions