Project

General

Profile

Actions

Bug #22602

closed

parse.y rejects `build 10 do end.transform () {}`

Bug #22602: parse.y rejects `build 10 do end.transform () {}`

Added by steviejj (Steven Johnstone) about 19 hours ago. Updated about 12 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27]
[ruby-core:127584]

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 Actions #1

  • 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 Actions #2

  • 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.

Actions

Also available in: PDF Atom