summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prism/prism.c12
-rw-r--r--test/prism/errors/def_ivar.txt3
2 files changed, 14 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 07d188dcc8..03b01cf7eb 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -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;
diff --git a/test/prism/errors/def_ivar.txt b/test/prism/errors/def_ivar.txt
new file mode 100644
index 0000000000..11620885cf
--- /dev/null
+++ b/test/prism/errors/def_ivar.txt
@@ -0,0 +1,3 @@
+def @foo; end
+ ^~~~ unexpected instance variable; expected a method name
+