🎃
[Bug #21014] prism で iseq から意図する node_id が取得できないバグ報告
[Bug #21014] Prism doesn't set node_id on iseqs correctly
-
prismで意図するnode_idが返ってこないバグ報告 - 以下のように
RubyVM::InstructionSequenceの情報からnode_idを取得するときの話みたいですね
f = proc { <<END }
heredoc
END
iseq = RubyVM::InstructionSequence.of(f)
p iseq.to_a[4][:node_id]
# prism => -1
# parse.y => 3
-
prismとparse.yでnode_idが一致していることを期待しているわけではないんですが、次のようなnode_idを基準として情報を取得するコードは動くことを期待しているみたいですね
f = proc { <<END }
heredoc
END
iseq = RubyVM::InstructionSequence.of(f)
require "prism"
# iseq の node_id を元にして Prism のパース結果を探す
node_id = iseq.to_a[4][:node_id]
ast = Prism.parse(File.binread(__FILE__))
p ast.value.breadth_first_search { |node| node.node_id == node_id }
# => nil
- この不具合は開発版の Ruby 3.5-dev ですでに修正済みです
f = proc { <<END }
heredoc
END
iseq = RubyVM::InstructionSequence.of(f)
require "prism"
# iseq の node_id を元にして Prism のパース結果を探す
node_id = iseq.to_a[4][:node_id]
ast = Prism.parse(File.binread(__FILE__))
p ast.value.breadth_first_search { |node| node.node_id == node_id }
# Ruby 3.4 => nil
# Ruby 3.5 =>
# @ BlockNode (location: (1,9)-(1,18))
# ├── flags: ∅
# ├── locals: []
# ├── parameters: ∅
# ├── body:
# ...
Discussion