summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-06-24 11:32:58 -0700
committerGitHub <[email protected]>2024-06-24 11:32:58 -0700
commitae0c7faa79029ebe615487d23c8ee1ca44ce4a36 (patch)
tree8c8afcacc8ae884f172b2d4d0bb4cd49141c3548 /compile.c
parente428ee7bbe07fd12f65e45be0839e7f0b1e4cda6 (diff)
Handle hash and splat nodes in defined?
This supports the nodes in both in the parse.y and prism compilers. Fixes [Bug #20043] Co-authored-by: Kevin Newton <[email protected]>
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/compile.c b/compile.c
index fee2fafc8d..62b5bbc490 100644
--- a/compile.c
+++ b/compile.c
@@ -5859,17 +5859,22 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
expr_type = DEFINED_FALSE;
break;
+ case NODE_HASH:
case NODE_LIST:{
- const NODE *vals = node;
+ const NODE *vals = (nd_type(node) == NODE_HASH) ? RNODE_HASH(node)->nd_head : node;
- do {
- defined_expr0(iseq, ret, RNODE_LIST(vals)->nd_head, lfinish, Qfalse, false);
+ if (vals) {
+ do {
+ if (RNODE_LIST(vals)->nd_head) {
+ defined_expr0(iseq, ret, RNODE_LIST(vals)->nd_head, lfinish, Qfalse, false);
- if (!lfinish[1]) {
- lfinish[1] = NEW_LABEL(line);
- }
- ADD_INSNL(ret, line_node, branchunless, lfinish[1]);
- } while ((vals = RNODE_LIST(vals)->nd_next) != NULL);
+ if (!lfinish[1]) {
+ lfinish[1] = NEW_LABEL(line);
+ }
+ ADD_INSNL(ret, line_node, branchunless, lfinish[1]);
+ }
+ } while ((vals = RNODE_LIST(vals)->nd_next) != NULL);
+ }
}
/* fall through */
case NODE_STR:
@@ -5889,6 +5894,15 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
expr_type = DEFINED_EXPR;
break;
+ case NODE_SPLAT:
+ defined_expr0(iseq, ret, RNODE_LIST(node)->nd_head, lfinish, Qfalse, false);
+ if (!lfinish[1]) {
+ lfinish[1] = NEW_LABEL(line);
+ }
+ ADD_INSNL(ret, line_node, branchunless, lfinish[1]);
+ expr_type = DEFINED_EXPR;
+ break;
+
/* variables */
case NODE_LVAR:
case NODE_DVAR: