From a9788d40a3e1cdce5e70cdff328b18524c10b86e Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Wed, 20 Nov 2024 16:20:38 +0000 Subject: [PATCH] [prism/compiler] end_cursor should never be NULL This fixes a failed assertion reported to SimpleCov https://github.com/simplecov-ruby/simplecov/issues/1113 The smallest repro I can make consists of 2 files test.rb containing the following code: ``` require 'coverage' Coverage.start(branches: true) require_relative 'broken.rb' ``` and `broken.rb` containing this ``` @foo&.bar(@baz) ``` --- prism_compile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/prism_compile.c b/prism_compile.c index fe5fde8d6305f6..d82bf5f582244c 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3630,6 +3630,7 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c const uint8_t *end_cursor = cursors[0]; end_cursor = (end_cursor == NULL || cursors[1] == NULL) ? cursors[1] : (end_cursor > cursors[1] ? end_cursor : cursors[1]); end_cursor = (end_cursor == NULL || cursors[2] == NULL) ? cursors[2] : (end_cursor > cursors[2] ? end_cursor : cursors[2]); + if (!end_cursor) end_cursor = scope_node->parser->newline_list.start; const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, call_node); const pm_line_column_t end_location = pm_newline_list_line_column(&scope_node->parser->newline_list, end_cursor, scope_node->parser->start_line);