[ruby/prism] Error for def ivar

https://github.com/ruby/prism/commit/232a02acef
This commit is contained in:
Kevin Newton 2024-11-03 13:28:33 -05:00 committed by git
parent 3e2ee99057
commit 21af248f92
2 changed files with 14 additions and 1 deletions

View File

@ -19212,6 +19212,10 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
context_push(parser, PM_CONTEXT_DEF_PARAMS);
parser_lex(parser);
// This will be false if the method name is not a valid identifier
// but could be followed by an operator.
bool valid_name = true;
switch (parser->current.type) {
case PM_CASE_OPERATOR:
pm_parser_scope_push(parser, true);
@ -19241,10 +19245,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
break;
}
case PM_TOKEN_CONSTANT:
case PM_TOKEN_INSTANCE_VARIABLE:
case PM_TOKEN_CLASS_VARIABLE:
case PM_TOKEN_GLOBAL_VARIABLE:
valid_name = false;
/* fallthrough */
case PM_TOKEN_CONSTANT:
case PM_TOKEN_KEYWORD_NIL:
case PM_TOKEN_KEYWORD_SELF:
case PM_TOKEN_KEYWORD_TRUE:
@ -19302,6 +19308,10 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
name = parse_method_definition_name(parser);
} else {
if (!valid_name) {
PM_PARSER_ERR_TOKEN_FORMAT(parser, identifier, PM_ERR_DEF_NAME, pm_token_type_human(identifier.type));
}
name = identifier;
}
break;

View File

@ -0,0 +1,3 @@
def @foo; end
^~~~ unexpected instance variable; expected a method name