[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
```
This commit is contained in:
eileencodes 2023-12-04 15:01:51 -05:00 коммит произвёл Jemma Issroff
Родитель 569750f624
Коммит c23b2e5353
2 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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