Bug #22602
closedparse.y rejects `build 10 do end.transform () {}`
Description
CRuby parse.y rejects chained method calls where a do ... end command call (block_call) is followed by whitespace, parenthesized command arguments, and a brace block (e.g. build 10 do end.transform () {}, minimized h 1do end.u (){}), raising SyntaxError: syntax error, unexpected { arg, expecting end-of-input. However, build 10 do end.transform(){} (no space before ()), build 10 do end.transform () (no trailing {} block), build 10 do end.transform 1 do end, and build(10){}.transform (){} all parse in both parse.y and Prism, and Prism accepts build 10 do end.transform () {} cleanly.
Discovered by differential fuzzing (actual find was h 1do end.u (){}).
Reproduction¶
Tested on CRuby ruby 4.1.0dev (2026-11-18T09:19:17Z HEAD ed3e747aa4) +PRISM [aarch64-linux] and ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27] (--parser=parse.y vs --parser=prism):
# Valid Ruby: chained `.transform () { ... }` after a `do ... end` command call
# CRuby 4.0.9 `--parser=prism`: exits 0 and outputs `:empty` (`()` passes `nil` to `arg`)
# CRuby 4.0.9 `--parser=parse.y`:
# SyntaxError: syntax error, unexpected { arg, expecting end-of-input
class Wrapper
def transform(arg = nil) = yield(arg)
end
def build(value)
yield(value)
Wrapper.new
end
result = build 10 do |value|
value * 2
end.transform () { |item| item.nil? ? :empty : item }
p result
Related syntax variants accepted by CRuby parse.y:
ruby --parser=parse.y -ce 'build 10 do end.transform(){}' # no space before `()`
ruby --parser=parse.y -ce 'build 10 do end.transform ()' # no trailing `{}` block
ruby --parser=parse.y -ce 'build 10 do end.transform 1 do end' # `do ... end` instead of `{}`
ruby --parser=parse.y -ce 'build(10){}.transform (){}' # parenthesized receiver call
Updated by nobu (Nobuyoshi Nakada) about 12 hours ago
- Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED
Updated by nobu (Nobuyoshi Nakada) about 12 hours ago
- Status changed from Open to Closed
Applied in changeset git|3288e455a00fa2b1d347b683cc4a055cd2fe2e04.
[Bug #22602] Handle command_args with brace-block after do-block
Support calls with parenthesized arguments followed by a brace
block after a do block.