Repository navigation
Commit e66e0cd
kernel: Kernel#loop rescues StopIteration + blockless Enumerator; add Kernel#fail (#599)
* kernel: Kernel#loop rescues StopIteration + blockless Enumerator; add Kernel#fail
Kernel#loop (internal/vm/builtins.go):
- With no block, return an infinite Enumerator over Kernel#loop whose #size is
Float::INFINITY (was: raise LocalJumpError). loop.each re-drives loop with the
given block. Ref: ruby/ruby v3_4_0 eval.c rb_f_loop / loop_size.
- A StopIteration (or subclass) raised in the block now ends the loop cleanly and
loop returns that exception's #result; every other exception (and break) still
propagates. Ref: eval.c rb_f_loop (rb_rescue2 over StopIteration).
Verified byte-for-byte vs MRI 4.0.5 for: rescue StopIteration, rescue a
StopIteration subclass, StopIteration#result, does-not-rescue-StandardError,
break value, blockless enumerator, loop.size == Float::INFINITY.
Kernel#fail: a genuine alias of Kernel#raise (shared method record via
aliasBuiltin), mirrored onto the Kernel module beside "raise" so
Kernel.instance_method(:fail) == …(:raise) and Kernel.method(:fail) == …(:raise),
with fail private on instances and Kernel.fail public. Ref: eval.c rb_f_raise
registered under both names. Verified vs MRI 4.0.5.
core/kernel: pass 1822 -> 1829, error 135 -> 128 (loop x5, fail x2); fail count
unchanged. ruby/spec corpus @ 87b1631992.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* kernel: tests for Kernel#loop StopIteration/blockless-Enumerator and Kernel#fail
New whitebox suite (internal/vm/kernel_loop_fail_wave21_internal_test.go, package
vm) covers every new branch: loop rescuing StopIteration and a subclass, the
StopIteration#result return, a break unwinding through the recover, propagation
of a non-StopIteration error (the panic re-raise), the blockless Enumerator +
Float::INFINITY size, and Kernel#fail sharing raise's instance/singleton records.
Updated TestLoopNoBlock (phase5w_test.go): blockless Kernel#loop now returns an
infinite Enumerator (MRI eval.c rb_f_loop), not a LocalJumpError; the assertion
is pinned to the MRI 4.0.5 behaviour and the now-unused strings import dropped.
vm package: all tests pass, 99.9% coverage; the new branches are covered and
bootstrap holds at its pre-existing 99.7%.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 415efad commit e66e0cd
3 files changed
Lines changed: 121 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
| 312 | + | |
313 | 313 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
318 | 336 | | |
319 | 337 | | |
320 | 338 | | |
| |||
1020 | 1038 | | |
1021 | 1039 | | |
1022 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
1023 | 1047 | | |
1024 | 1048 | | |
1025 | 1049 | | |
| |||
6223 | 6247 | | |
6224 | 6248 | | |
6225 | 6249 | | |
6226 | | - | |
| 6250 | + | |
6227 | 6251 | | |
6228 | 6252 | | |
6229 | 6253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
27 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
0 commit comments