Skip to content

Commit ad96c5a

Browse files
eileencodesmatzbot
authored andcommitted
[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 ruby/prism@43c16a89ef
1 parent d0f9f3e commit ad96c5a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

prism/prism.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,9 +1740,10 @@ char_is_global_name_punctuation(const uint8_t b) {
17401740
static inline bool
17411741
token_is_setter_name(pm_token_t *token) {
17421742
return (
1743-
(token->type == PM_TOKEN_IDENTIFIER) &&
1743+
(token->type == PM_TOKEN_BRACKET_LEFT_RIGHT_EQUAL) ||
1744+
((token->type == PM_TOKEN_IDENTIFIER) &&
17441745
(token->end - token->start >= 2) &&
1745-
(token->end[-1] == '=')
1746+
(token->end[-1] == '='))
17461747
);
17471748
}
17481749

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
def a=() = 42
22
^~ invalid method name; a setter method cannot be defined in an endless method definition
33

4+
def []=() = 42
5+
^~~ invalid method name; a setter method cannot be defined in an endless method definition
6+

0 commit comments

Comments
 (0)