65 Commits

Author SHA1 Message Date
Earlopain
e7d2828fb6 [ruby/prism] Fix error message for block/lambda with ... argument
They currently complain that the parent method is not forwarding.
But the actual problem is that these types of arguments simply don't
accept `...`

Fixes [Bug #21927]

https://github.com/ruby/prism/commit/0aa2363331
2026-03-06 09:02:23 -08:00
Takashi Kokubun
a10f7fac1f Sync Prism to 1.8.0 2026-01-12 17:59:55 -08:00
Earlopain
e2c886dd66 [ruby/prism] Reject p(p a, &block => value) and similar
Redo of https://github.com/ruby/prism/pull/3669 with more tests

https://github.com/ruby/prism/commit/48b403ea79
2025-12-18 19:58:53 -05:00
Earlopain
465a86c341 [ruby/prism] Fix %Q with newline delimiter and heredoc interpolation
The lexer did not jump to the `heredoc_end`, causing the heredoc end delimiter
to be parsed twice.

Normally the heredocs get flushed when a newline is encountered. But because
the newline is part of the string delimiter, that codepath is not taken.

Fixes [Bug #21758]

https://github.com/ruby/prism/commit/7440eb4b11
2025-12-04 14:50:46 +00:00
Kevin Newton
b1314f159e [ruby/prism] Fully destroy call operator write arguments
If we are about to delete a call operator write argument, it needs
to be removed from the list of block exits as well.

https://github.com/ruby/prism/commit/ebc91c2e39
2025-11-30 02:08:41 +00:00
Kevin Newton
7c2eb946e0 [ruby/prism] Fix label interpolated string
https://github.com/ruby/prism/commit/e3e2b1ed04
2025-11-29 19:48:30 +00:00
Kevin Newton
f2a6cb2dc8 [ruby/prism] Handle invalid string pattern key
When a pattern match is using a string as a hash pattern key and is
using it incorrectly, we were previously assuming it was a symbol.
In the case of an error, that's not the case. So we need to add a
missing node in this case.

https://github.com/ruby/prism/commit/f0b06d6269
2025-11-29 19:47:45 +00:00
Kevin Newton
b75cf83a33 [ruby/prism] Revert "Reject p(p a, &block => value) and similar"
https://github.com/ruby/prism/commit/fef2c20777
2025-11-23 21:36:19 +00:00
Earlopain
2870b7d7df [ruby/prism] Reject p(p a, &block => value) and similar
They were being parsed as `p((p a, &block) => value)`.
When we get to this point, we must not just have parsed a command call, always consuming the `=>` is not correct.

Closes [Bug #21622]

https://github.com/ruby/prism/commit/796ab0edf4
2025-11-23 18:15:15 +00:00
Kevin Newton
8d0105824f Handle deeply nested capture variables syntax err
When there are nested capture variables inside of a pattern match
that has an alternation pattern, it is a syntax error. Currently it
only adds a syntax error when it is at the top level of the pattern.
2025-11-16 21:30:24 -05:00
Earlopain
bec69617a0 [ruby/prism] Reject endless method as a block parameter default
Fixes [Bug #21661]

https://github.com/ruby/prism/commit/475fa46a82
2025-11-14 16:27:38 +00:00
Earlopain
d73eba5185 [ruby/prism] Reject def f a, (b) = 1
Fixes [#Bug 21660], followup to https://github.com/ruby/prism/pull/3674

https://github.com/ruby/prism/commit/fb445a49e5

Co-Authored-By: tomoya ishida <tomoyapenguin@gmail.com>
2025-11-06 13:31:46 +00:00
Earlopain
6047eada20 [ruby/prism] Make error and snapshot tests multi-version aware
This one has been on my mind for a while now.

Currently, there are only tests against the latest syntax version.

This changes the snapshot structure as follows:
* Snapshots at their current location are tested against all syntax versions
* Snapshots inside a version folder like "3.3" are tested against all versions starting from that version
* Snapshots inside a version folder like "3.3-4.2" are tested against all versions in the given range.

This makes sure that as new syntax is added, older versions still work as expected.
I also added a few tests for now valid syntax that should be invalid in older versions (and the other way around as well)

These tests run really fast. So even though it does 3x the work for these, I am still able to run the whole test suite in just 11 seconds.

https://github.com/ruby/prism/commit/5191b1aa68
2025-10-22 14:50:11 +00:00
Earlopain
b8f8d646a6 [ruby/prism] For these special cases, there exists no optional argument type. Since a endless method is started with =, there was ambiguity here. We have to simply reject these in all cases.
This adds a new error for the following reason:
* `def foo arg = nil` is interpreted as a normal method call with optional `arg` without matching `end`
* `def foo *arg = nil; end` is interpreted as a endless method call that has body `nil` with extraneous `end`

`def foo *arg = nil` is somewhere inbetween and I don't know how to otherwise indicate the error.
Now the second case above also shows the newly added error message.

Fixes [Bug #21623]

https://github.com/ruby/prism/commit/e1910d4492
2025-10-08 13:04:57 +00:00
Earlopain
71067aa54c [ruby/prism] Reject argument command call taking a block with more trailing arguments
https://bugs.ruby-lang.org/issues/21168#note-5

The added code samples align with `parse.y`, except for `foo(bar baz do end)` which `parse.y` currently rejects but shouldn't.

https://github.com/ruby/prism/commit/3a4e102d80
2025-09-19 16:55:01 +00:00
Earlopain
3c7a89721d [ruby/prism] Reject 1 if foo = bar baz
and also `1 and foo = bar baz`

This is a partial fix for https://github.com/ruby/prism/issues/3106
It still accepts `a = b c and 1`

https://github.com/ruby/prism/commit/7a13d3535b
2025-09-17 16:39:27 +00:00
Earlopain
f2dbc4ec82 [ruby/prism] [Bug #17398] Allow private def hello = puts "Hello"
This was a limitation of parse.y that prism intentionally replicated.

https://github.com/ruby/prism/commit/8fd12d594c
2025-09-12 15:00:01 -04:00
Earlopain
f17405b69c [ruby/prism] Reject some cases with return and command calls
The same also applies to `break`/`next`.

https://bugs.ruby-lang.org/issues/21540

https://github.com/ruby/prism/commit/3a38b192e3
2025-09-11 15:55:55 +00:00
ydah
087190fcd2 [ruby/prism] Improve error handling for missing parentheses after 'not' in command calls
https://github.com/ruby/prism/commit/d9151b8a82
2025-08-05 13:58:09 -04:00
Yusuke Endoh
f814a77755 [ruby/prism] Reject true && not true
A command-call-like `not true` must be rejected after `&&` and `||`.

https://bugs.ruby-lang.org/issues/21337

https://github.com/ruby/prism/commit/0513cf22ad
2025-08-05 13:58:09 -04:00
Stan Lo
2eab962c53 [ruby/prism] Allow command calls in endless method bodies within assignments
Previously, endless method definitions in assignment contexts like
`x = def f = p 1` would fail to parse because command calls (method
calls without parentheses) were only accepted when the surrounding
binding power was less than `PM_BINDING_POWER_COMPOSITION`.

This fix specifically checks for assignment context and allows command
calls in those cases while maintaining the existing behavior for other
contexts. This ensures that:

- `x = def f = p 1` parses correctly (previously failed)
- `private def f = puts "Hello"` still produces the expected error

https://github.com/ruby/prism/commit/722af59ba3
2025-07-29 17:18:41 +00:00
Earlopain
133cf95618 [ruby/prism] [Bug #21345] Fix accepting multiple rest patterns with leading match
Related:
* https://bugs.ruby-lang.org/issues/20765
* https://github.com/ruby/prism/issues/2915

https://github.com/ruby/prism/commit/de56fa4a34
2025-07-16 18:12:06 +00:00
Stan Lo
2591b93593 [ruby/prism] Fix crash when using arithmetic expressions in pattern matching
When arithmetic expressions like `-1**2` are used in pattern matching contexts,
Ruby crashes with "Unexpected node type in pattern matching expression: PM_CALL_NODE".
This happens because the Prism parser creates `PM_CALL_NODE` for arithmetic operations,
but Ruby's pattern matching compiler doesn't handle call nodes.

This fix adds validation to reject `PM_CALL_NODE` in pattern contexts with a proper
syntax error.

https://github.com/ruby/prism/commit/365049a767
2025-07-16 17:08:28 +00:00
ydah
4eb0a6cd4d [ruby/prism] Improve error handling for missing parentheses after 'not' in command calls
https://github.com/ruby/prism/commit/d9151b8a82
2025-07-16 15:48:09 +00:00
Yusuke Endoh
4cf85fe214 [ruby/prism] Reject true && not true
A command-call-like `not true` must be rejected after `&&` and `||`.

https://bugs.ruby-lang.org/issues/21337

https://github.com/ruby/prism/commit/0513cf22ad
2025-07-16 15:48:09 +00:00
Kevin Newton
052794bfe1 [ruby/prism] Accept a newline after the defined? keyword
[Bug #21197]

https://github.com/ruby/prism/commit/22be955ce9
2025-03-30 13:22:41 -04:00
Kevin Newton
3d6fc29169 [ruby/prism] Make xstrings concat syntax error
https://github.com/ruby/prism/commit/f734350499
2025-03-18 16:00:03 +00:00
Kevin Newton
2db365dc83 [ruby/prism] Fix escape unicode curly inline whitespace
Fixes [Bug #21145]

https://github.com/ruby/prism/commit/be2d845639
2025-02-17 18:12:03 +00:00
Kevin Newton
127325a4ba [ruby/prism] No writing to numbered parameters
Fixes [Bug #21117]

https://github.com/ruby/prism/commit/19d4bab5a0
2025-02-13 20:04:02 +00:00
Kevin Newton
b21e1aed2e [ruby/prism] Fix infinite loop in error recovery
When recovering from a depth error that occurs at the end of the
file, we need to break out of parsing statements.

Fixes [Bug #21114]

https://github.com/ruby/prism/commit/a32e268787
2025-02-13 19:12:10 +00:00
ydah
ca81142eff [ruby/prism] [Bug #21010] Reject endless method definition of []=
Fixes: https://bugs.ruby-lang.org/issues/20785

https://github.com/ruby/prism/commit/192960ce5d
2025-01-11 19:09:05 -05:00
Kevin Newton
96f23306f0 [ruby/prism] Revert "Reject pattern match with unexpected double splat inside array"
https://github.com/ruby/prism/commit/51e7c84124
2025-01-08 20:42:35 +00:00
ydah
500a87756f [ruby/prism] Reject pattern match with unexpected double splat inside array
`a => [-2**b]` should be SyntaxError

Fixes: https://github.com/ruby/prism/issues/3381

https://github.com/ruby/prism/commit/ae8e83b389
2025-01-08 17:23:51 +00:00
eileencodes
ad96c5a729 [ruby/prism] Throw syntax error for endless method with []=
Prism shoudld throw a syntax error for endless methods when the method
name uses brackets. Previously it would not. This matches the behavior
of parse.y.

Fixes https://bugs.ruby-lang.org/issues/21010

https://github.com/ruby/prism/commit/43c16a89ef
2025-01-07 19:35:01 +00:00
Junichi Ito
c8e3d745fa Use a single quote instead of a backtick for error messages
Fix https://bugs.ruby-lang.org/issues/20977
2025-01-05 20:50:53 -05:00
eileencodes
a21237571e [ruby/prism] Fix 3112 - disallow commas after block arg
Prism was already disallowing arguments after block args, but in
parse.y, any comma after a block arg is a syntax error. This moves the
error handling into `PM_TOKEN_UAMPERSAND` where we can check if the
current type is `PM_TOKEN_COMMA`then raise an error. I've also updated
the tests to include the examplesfrom ruby/prism#3112.

Fixes: ruby/prism#3112

https://github.com/ruby/prism/commit/754cf8eddc
2024-12-16 10:51:22 -05:00
Matt Valentine-House
b37777c36f [PRISM] Blocks are also a syntax error in array assignment
Actually close [Bug #20952]
2024-12-13 22:02:06 +00:00
Matt Valentine-House
e194665720 [PRISM] using []= to set kwargs is a syntax error
Fixes [Bug #20952]
2024-12-13 21:22:35 +00:00
Aaron Patterson
0a1fa99482 [ruby/prism] Same numbered param cannot be used in child blocks
Raise an exception when the same numbered param is used inside a child
block.  For example, the following code should be a syntax error:

```ruby
-> { _1 + -> { _1 } }
```

Fixes https://github.com/ruby/prism/pull/3291

https://github.com/ruby/prism/commit/d4fc441838
2024-12-12 00:42:27 +00:00
Aaron Patterson
6877c38866 [ruby/prism] Fix error messages for unterminated ( and {
If we hit an EOF token, and the character before the EOF is a newline,
we should make EOF token start at the previous newline.  That way any
errors reported will occur on that line.

For example "foo(\n" should report an error on line 1 even though the
EOF technically occurs on line 2.

[Bug #20918]
https://bugs.ruby-lang.org/issues/20918

https://github.com/ruby/prism/commit/60bc43de8e
2024-12-05 18:42:01 +00:00
ydah
fd217d475d [ruby/prism] Reject invalid operator after match predicate or after match required
Partially fixes: #3171

https://github.com/ruby/prism/commit/d0d9699c27
2024-12-02 18:42:16 +00:00
ydah
2ba5987263 [ruby/prism] Reject invalid dot method call after match predicate or after match required
Partially fixes:  https://github.com/ruby/prism/issues/3171

https://github.com/ruby/prism/commit/5c33fa5a1a
2024-12-02 18:41:38 +00:00
ydah
aa77bfd13e [ruby/prism] Reject extra comma in array after keyword argument
Fixes: https://github.com/ruby/prism/issues/3109

https://github.com/ruby/prism/commit/9ed989c30d
2024-12-02 18:39:49 +00:00
Haldun Bayhantopcu
6767117b07 [ruby/prism] Fix splat after kwsplat
https://github.com/ruby/prism/commit/70c1cd480f
2024-11-08 15:50:54 +00:00
Kevin Newton
21af248f92 [ruby/prism] Error for def ivar
https://github.com/ruby/prism/commit/232a02acef
2024-11-03 18:43:18 +00:00
Kevin Newton
82c76f1896 [ruby/prism] Reject invalid splat as last statement of parentheses
https://github.com/ruby/prism/commit/3a0b1c6110
2024-10-10 14:45:59 +00:00
Kevin Newton
4cbd2ab9d4 [ruby/prism] Properly handle non-assoc operators
https://github.com/ruby/prism/commit/dbd5c929d6
2024-10-07 17:57:36 +00:00
Kevin Newton
8d1906e8b7 [ruby/prism] Handle invalid commas in arguments, parameters, and arrays
https://github.com/ruby/prism/commit/023e894b74
2024-10-07 16:38:16 +00:00
Kevin Newton
75640037bf [ruby/prism] Fix up multi target parsing
https://github.com/ruby/prism/commit/80cd335222
2024-10-04 16:22:21 +00:00
Kevin Newton
f8568fbd7f [ruby/prism] Pop lex mode for heredocs in the lexer, not the parser
https://github.com/ruby/prism/commit/5dd36b979e
2024-10-03 17:30:20 +00:00