From 33bc22efe5d372898f3a37004f324f7457e9a944 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 4 Dec 2023 15:10:12 -0500 Subject: [PATCH] [PRISM] Implement `PM_INTERPOLATED_STRING_NODE` Implements `PM_INTERPOLATED_STRING_NODE` for `defined?` Code: ```ruby defined?("#{expr}") ``` ``` "********* Ruby *************" == disasm: #@:0 (0,0)-(0,19)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #@:0 (0,0)-(0,19)> 0000 putobject "expression" 0002 leave ``` --- prism_compile.c | 1 + test/ruby/test_compile_prism.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/prism_compile.c b/prism_compile.c index 3c081cbafa..ad038a2ed6 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1478,6 +1478,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co case PM_FLOAT_NODE: case PM_HASH_NODE: case PM_INTEGER_NODE: + case PM_INTERPOLATED_STRING_NODE: case PM_LAMBDA_NODE: case PM_OR_NODE: case PM_RANGE_NODE: diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index b6b1274ea8..e77051e383 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -102,6 +102,7 @@ module Prism assert_prism_eval("defined? [1, 2, 3]") assert_prism_eval("defined?({ a: 1 })") assert_prism_eval("defined? 'str'") + assert_prism_eval('defined?("#{expr}")') assert_prism_eval("defined? :sym") assert_prism_eval("defined? /foo/") assert_prism_eval("defined? -> { 1 + 1 }")