Commit 9406ad2
Two bugs made `r = []; Enumerator.new { |y| r << y.yield(1) }.to_a; p r`
abort the process (non-unwinding panic in `Value::as_array`):
1. The generator driver `generator_yield_values` resumed the fiber with the
`yielder` on *every* activation. The yielder is only the block parameter
on the first (Created) activation; on later resumes that value becomes
the return value of the `y.yield(...)` that suspended, so `Yielder#yield`
returned the Yielder itself instead of nil (CRuby returns nil for
each/to_a). That leaked a Yielder into user data. Resume with `Value::nil()`.
2. `Enumerator::Yielder` was defined as a subclass of `Array`, but a yielder
is a plain OBJECT-typed RValue. Inherited `Array#inspect` (etc.) then ran
`Value::as_array` on a non-array and hit the assertion, aborting the
process the moment such a leaked Yielder was inspected. Make `Yielder`
inherit `Object`, as in CRuby (`Enumerator::Yielder.superclass == Object`);
its `<<` / `yield` are defined directly.
With both fixes the repro prints `[nil]` and `Yielder#yield` returns nil,
matching CRuby. core/enumerator/new_spec no longer crashes and its
`#yield returns nil` example passes, so its spec/tags entry is removed.
Full lib suite: 1828 passed.
Claude-Session: https://claude.ai/code/session_01XpzdoFu46d2ChJpSzeWsNK
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 498118c commit 9406ad2
4 files changed
Lines changed: 58 additions & 16 deletions
File tree
- doc
- monoruby/src
- builtins
- value/rvalue
- spec/tags/core/enumerator
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
205 | 202 | | |
206 | 203 | | |
207 | 204 | | |
208 | 205 | | |
209 | 206 | | |
210 | 207 | | |
211 | 208 | | |
212 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
461 | 466 | | |
462 | 467 | | |
463 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
464 | 497 | | |
465 | 498 | | |
466 | 499 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | 142 | | |
136 | 143 | | |
| |||
This file was deleted.
0 commit comments