whitequark / parser

A Ruby parser.
Other
1.59k stars 199 forks source link

Parsing for `-> { yield }` is not compatible with Ruby 3.3+ #1042

Open koic opened 1 month ago

koic commented 1 month ago

The following changes have been made between Ruby 3.2 and earlier and 3.3 and later:

Ruby 3.2 and earlier:

$ ruby -vce '-> { yield }'
ruby 3.2.4 (2024-04-23 revision af471c0e01) [x86_64-darwin23]
Syntax OK

Ruby 3.3 and later:

$ ruby -vce '-> { yield }'
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin23]
-e:1: Invalid yield
-> { yield }
ruby: compile error (SyntaxError)

Expected Behavior:

In Ruby 3.3 and later, the expression -> { yield } raises a syntax error.

Actual Behavior:

The latest version of the Parser gem (3.3.5.0) still follows the behavior of Ruby 3.2 and earlier, which successfully parsed without parse error when attempting to parse -> { yield }.

For example:

$ ruby-parse --32 -e '-> { yield }'
(block
  (lambda)
  (args)
  (yield))

$ ruby-parse --33 -e '-> { yield }'
(block
  (lambda)
  (args)
  (yield))
iliabylich commented 1 month ago

Correct, it's a documented incompatibility. parser doesn't do checks that MRI does outside of parse.y (in compile.c in this case I believe)