Open herwinw opened 3 weeks ago
p [:a].each_with_index.map { |value, idx| [value, idx] }
This appears to be working, so this bug is probably specific for with_index
and not a generic bug. I've used this one as a mitigation for the issue in #2145, I have to admit this one is a bit more readable as well.
Observed in #2145 where it broke our self hosted compiler. This snippet:
The output of MRI (I used version 3.3.3, but it should be the same in any supported version):
The output of the same program ran with Natalie:
The call to
Enumerator#with_index
is supposed to return a new Enumerator if no block is given, but should return an array if a block is given. Additionally, the output of[:a].map.with_index { |value, idx| [value, idx] }.to_a
is the original array, not the mapped version.