[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
This commit is contained in:
eileencodes 2025-01-07 14:18:20 -05:00 committed by git
parent d0f9f3e2c6
commit ad96c5a729
2 changed files with 6 additions and 2 deletions

View File

@ -1740,9 +1740,10 @@ char_is_global_name_punctuation(const uint8_t b) {
static inline bool
token_is_setter_name(pm_token_t *token) {
return (
(token->type == PM_TOKEN_IDENTIFIER) &&
(token->type == PM_TOKEN_BRACKET_LEFT_RIGHT_EQUAL) ||
((token->type == PM_TOKEN_IDENTIFIER) &&
(token->end - token->start >= 2) &&
(token->end[-1] == '=')
(token->end[-1] == '='))
);
}

View File

@ -1,3 +1,6 @@
def a=() = 42
^~ invalid method name; a setter method cannot be defined in an endless method definition
def []=() = 42
^~~ invalid method name; a setter method cannot be defined in an endless method definition