From: "kddnewton (Kevin Newton) via ruby-core" Date: 2026-10-15T20:14:59+00:00 Subject: [ruby-core:127131] [Ruby Bug#22447] parse.y `-> do ... end` COND state Issue #22447 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Bug #22447: parse.y `-> do ... end` COND state https://bugs.ruby-lang.org/issues/22447 * Author: kddnewton (Kevin Newton) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- With parse.y, `do`-blocks inside a `-> do ... end` lambda body are rejected when the lambda appears in a `while`/`until`/`for` condition: ```ruby while -> do foo do end end; end # => syntax error, unexpected 'do' for condition, expecting 'end' or dummy end ``` The same body is accepted outside a condition, and with brace delimiters inside one: ```ruby -> do foo do end end # OK while -> { foo do end }; end # OK while (foo do end); end # OK while def m; foo do end; end; end # OK while -> do foo do end end; end # SyntaxError until -> do foo do end end; end # SyntaxError for x in -> do foo do end end do end # SyntaxError ``` Nesting a `-> do` lambda in an unparenthesized lambda parameter default also triggers it: ```ruby while -> a = -> do foo do end end do end; end # SyntaxError ``` Pretty much everywhere this kind of thing happens there is a pair of `CMDARG_PUSH(0)` and `COND_PUSH(0)`, but lambda is missing the latter. I think that's really all that needs to change to make this work: ```diff --- a/parse.y +++ b/parse.y @@ lambda : tLAMBDA[lpar] f_larglist[args] { CMDARG_PUSH(0); + COND_PUSH(0); } lambda_body[body] { @@ restore_block_exit(p, $al + COND_POP(); CMDARG_POP(); ``` It looks like this was fixed in other places (test_methoddef_in_cond and test_classdef_in_cond both test this kind of thing). -- 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/