From 8f69c5af08650c113fd68c2a75ba30b06b506e2f Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 15 Jan 2026 21:47:26 +0100 Subject: [PATCH] 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. --- src/prism.c | 2 +- test/prism/errors_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/prism.c b/src/prism.c index b36a6da204..b158e505b2 100644 --- a/src/prism.c +++ b/src/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 @@ def test_regexp_encoding_option_mismatch_error 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)