diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 17:54:21 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 17:54:21 -0800 |
| commit | 9240f01b1fbe5ea4f6a2017d35f8f605f84f0039 (patch) | |
| tree | 876760a93f9818edaf31bbc968baae23e96342ca | |
| parent | c3d30e4dabb2b895c347e10221467dd1b1124ca4 (diff) | |
merge revision(s) 63723c8d5908569918fb27e070ae5bc9de33c8bd: [Backport #21014]
Correctly set node_id on iseq location
The iseq location object has a slot for node ids. parse.y was correctly
populating that field but Prism was not. This commit populates the field
with the ast node id for that iseq
[Bug #21014]
| -rw-r--r-- | iseq.c | 2 | ||||
| -rw-r--r-- | prism_compile.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 6 | ||||
| -rw-r--r-- | version.h | 2 |
4 files changed, 10 insertions, 4 deletions
@@ -1072,7 +1072,7 @@ pm_iseq_new_with_opt(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpa .end_pos = { .lineno = (int) end.line, .column = (int) end.column } }; - prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_location, -1, + prepare_iseq_build(iseq, name, path, realpath, first_lineno, &code_location, node->ast_node->node_id, parent, isolated_depth, type, node->script_lines == NULL ? Qnil : *node->script_lines, option); struct pm_iseq_new_with_opt_data data = { diff --git a/prism_compile.c b/prism_compile.c index 8bef6ce747..a63bf490f5 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -6482,7 +6482,7 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod case ISEQ_TYPE_BLOCK: { LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0); LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0); - const pm_node_location_t block_location = { .line = body->location.first_lineno, .node_id = -1 }; + const pm_node_location_t block_location = { .line = body->location.first_lineno, .node_id = scope_node->ast_node->node_id }; start->rescued = LABEL_RESCUE_BEG; end->rescued = LABEL_RESCUE_END; @@ -6608,7 +6608,7 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod } if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) { - const pm_node_location_t location = { .line = ISEQ_COMPILE_DATA(iseq)->last_line, .node_id = -1 }; + const pm_node_location_t location = { .line = ISEQ_COMPILE_DATA(iseq)->last_line, .node_id = scope_node->ast_node->node_id }; PUSH_INSN(ret, location, leave); } } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 33a8b17b99..a2e8b7bd97 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -3,6 +3,12 @@ # This file is organized to match itemization in https://github.com/ruby/prism/issues/1335 module Prism class TestCompilePrism < Test::Unit::TestCase + def test_iseq_has_node_id + code = "proc { <<END }\n hello\nEND" + iseq = RubyVM::InstructionSequence.compile_prism(code) + assert_operator iseq.to_a[4][:node_id], :>, -1 + end + # Subclass is used for tests which need it class Subclass; end ############################################################################ @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 8 +#define RUBY_PATCHLEVEL 9 #include "ruby/version.h" #include "ruby/internal/abi.h" |
