aboutsummaryrefslogtreecommitdiffstats
path: root/prism_compile.c
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2023-12-05 13:47:46 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-12-06 09:46:19 -0500
commit86497645229099f3a6d0f64b3bb85d215f04f5df (patch)
tree41aef919ae1f1d3df6fb4140e59b80aec78453cc /prism_compile.c
parent02961fdbab0da97b2aa506b3e77d846d7e883ddc (diff)
downloadruby-86497645229099f3a6d0f64b3bb85d215f04f5df.tar.gz
[PRISM] Implement `PM_SPLAT_NODE` for `defined?`
In an array for `defined?` we need to check if there is a `contains_splat` flag, if so bail early. Ruby code: ```ruby defined?([[*1..2], 3, *4..5]) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,29)> 0000 putobject "expression" 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:0 (0,0)-(0,29)> 0000 putobject "expression" 0002 leave ```
Diffstat (limited to 'prism_compile.c')
-rw-r--r--prism_compile.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 15c672cd61..695dcc5ab9 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -1472,12 +1472,14 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co
break;
case PM_ARRAY_NODE: {
pm_array_node_t *array_node = (pm_array_node_t *) node;
- for (size_t index = 0; index < array_node->elements.size; index++) {
- pm_compile_defined_expr0(iseq, array_node->elements.nodes[index], ret, src, popped, scope_node, dummy_line_node, lineno, true, lfinish);
- if (!lfinish[1]) {
- lfinish[1] = NEW_LABEL(lineno);
- }
- ADD_INSNL(ret, &dummy_line_node, branchunless, lfinish[1]);
+ if (!(array_node->base.flags & PM_ARRAY_NODE_FLAGS_CONTAINS_SPLAT)) {
+ for (size_t index = 0; index < array_node->elements.size; index++) {
+ pm_compile_defined_expr0(iseq, array_node->elements.nodes[index], ret, src, popped, scope_node, dummy_line_node, lineno, true, lfinish);
+ if (!lfinish[1]) {
+ lfinish[1] = NEW_LABEL(lineno);
+ }
+ ADD_INSNL(ret, &dummy_line_node, branchunless, lfinish[1]);
+ }
}
}
case PM_AND_NODE: