aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2023-12-04 15:01:51 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-12-04 16:45:18 -0500
commitc23b2e5353f08a7131c77567f89d3aae707bdd25 (patch)
tree2c927c69111beb1f677e47d3498a91cb547665ab
parent569750f624dbb4e9d5836d4e9c46816224f4b681 (diff)
downloadruby-c23b2e5353f08a7131c77567f89d3aae707bdd25.tar.gz
[PRISM] Fix `PM_PARENTHESES_NODE`
In #9101 I only accounted for an empty paren. This change implements the `PM_PARENTHESES_NODE` for when it's `nil` and when it's an expression. Code: ```ruby defined?(("a")) ``` ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,15)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,15)> 0000 putobject "expression" 0002 leave ```
-rw-r--r--prism_compile.c11
-rw-r--r--test/ruby/test_compile_prism.rb1
2 files changed, 11 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c
index e29e57721a..3c081cbafa 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -1443,9 +1443,18 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co
enum defined_type dtype = DEFINED_NOT_DEFINED;
switch (PM_NODE_TYPE(node)) {
case PM_NIL_NODE:
- case PM_PARENTHESES_NODE:
dtype = DEFINED_NIL;
break;
+ case PM_PARENTHESES_NODE: {
+ pm_parentheses_node_t *parentheses_node = (pm_parentheses_node_t *) node;
+
+ if (parentheses_node->body == NULL) {
+ dtype = DEFINED_NIL;
+ } else {
+ dtype = DEFINED_EXPR;
+ }
+ break;
+ }
case PM_SELF_NODE:
dtype = DEFINED_SELF;
break;
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 922640982e..b6b1274ea8 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -158,6 +158,7 @@ module Prism
assert_prism_eval("if defined? A; end")
assert_prism_eval("defined?(())")
+ assert_prism_eval("defined?(('1'))")
end
def test_GlobalVariableReadNode