diff --git a/prism/prism.c b/prism/prism.c index 4f65e1e017..368a6c12ab 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -16444,7 +16444,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b (parser->current_context->context == PM_CONTEXT_CLASS) || (parser->current_context->context == PM_CONTEXT_MODULE) ) { - pm_parser_err_current(parser, PM_ERR_RETURN_INVALID); + pm_parser_err_previous(parser, PM_ERR_RETURN_INVALID); } return (pm_node_t *) pm_return_node_create(parser, &keyword, arguments.arguments); } diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index 9221d52ef3..6e6e74ee5d 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -1091,7 +1091,7 @@ module Prism ) assert_errors expected, "class A; return; end", [ - ["invalid `return` in a class or module body", 15..16] + ["invalid `return` in a class or module body", 9..15] ] end @@ -1106,7 +1106,7 @@ module Prism ) assert_errors expected, "module A; return; end", [ - ["invalid `return` in a class or module body", 16..17] + ["invalid `return` in a class or module body", 10..16] ] end