Skip to content

Commit 67c83af

Browse files
authored
Merge pull request #3377 from ruby/fix-21010
Throw syntax error for endless method with `[]=`
2 parents 005cbfa + 43c16a8 commit 67c83af

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/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)