summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEarlopain <14981592+Earlopain@users.noreply.github.com>2026-01-15 21:47:26 +0100
committergit <svn-admin@ruby-lang.org>2026-01-15 21:15:34 +0000
commitc34c7def5a13bcc60b09c1fc11267a6fdca700ba (patch)
treecf9db05912fd03237ededa60fae5988a97e7b42e
parent15939e3c30b9ab5e8623a8f78e4249b0e935bf3f (diff)
[ruby/prism] Fix locations for invalid syntax when using `expect1_opening`
Followup to https://github.com/ruby/prism/pull/3827 It sets the start to the opening but it should instead just continue on as usual. Fixes https://github.com/ruby/prism/issues/3851 Notice how the AST actually contains "123" in both the body and end keyword. https://github.com/ruby/prism/commit/8f69c5af08
-rw-r--r--prism/prism.c2
-rw-r--r--test/prism/errors_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c
index b36a6da204..b158e505b2 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -12438,7 +12438,7 @@ expect1_opening(pm_parser_t *parser, pm_token_type_t type, pm_diagnostic_id_t di
pm_parser_err(parser, opening->start, opening->end, diag_id);
- parser->previous.start = opening->end;
+ parser->previous.start = parser->previous.end;
parser->previous.type = PM_TOKEN_MISSING;
}
diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb
index 706b739557..aa264ae5b7 100644
--- a/test/prism/errors_test.rb
+++ b/test/prism/errors_test.rb
@@ -82,6 +82,11 @@ module Prism
assert_empty result.errors
end
+ def test_incomplete_def_closing_loc
+ statement = Prism.parse_statement("def f; 123")
+ assert_empty(statement.end_keyword)
+ end
+
private
def assert_errors(filepath, version)