From: "steviejj (Steven Johnstone) via ruby-core" Date: 2026-11-18T12:21:02+00:00 Subject: [ruby-core:127581] [Ruby Bug#22599] parse.y rejects valid retry after a class / class << self definition inside rescue (`Invalid retry after ensure`) Issue #22599 has been reported by steviejj (Steven Johnstone). ---------------------------------------- Bug #22599: parse.y rejects valid retry after a class / class << self definition inside rescue (`Invalid retry after ensure`) https://bugs.ruby-lang.org/issues/22599 * Author: steviejj (Steven Johnstone) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- In CRuby's `parse.y`, defining a class or singleton class (`class A; end` or `class << self; end`) inside a `rescue` clause causes a subsequent `retry` in the same `rescue` clause to fail compilation with `SyntaxError: Invalid retry after ensure`, even though no `ensure` clause exists. Defining a method (`def tmp; end`) inside `rescue` does not trigger this bug, and `--parser=prism` compiles and executes the `retry` cleanly. Discovered by differential fuzzing of prism against parse.y. ## Reproduction Tested on CRuby `4.1.0dev` (`2026-11-18 HEAD ed3e747aa4`) and `ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27]` ```ruby # 1. Singleton class inside rescue: n = 0 begin n += 1 raise if n == 1 rescue class << self; end retry end p n # --parser=prism: outputs `2` (exit 0) # --parser=parse.y: SyntaxError: Invalid retry after ensure (exit 1) ``` Same failure for a regular class definition (`class TmpC; end`): ```ruby n = 0 begin n += 1 raise if n == 1 rescue class TmpC; end retry end p n # --parser=prism: outputs `2` (exit 0) # --parser=parse.y: SyntaxError: Invalid retry after ensure (exit 1) ``` Control case (`def` instead of `class`): ```ruby n = 0 begin n += 1 raise if n == 1 rescue def tmp_x; end retry end p n # --parser=parse.y: outputs `2` (exit 0) # --parser=prism: outputs `2` (exit 0) ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/