aboutsummaryrefslogtreecommitdiffstats
path: root/prism_compile.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-12-06 11:05:43 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-12-06 11:31:43 -0500
commitf80262b14d01a977ce386a5a377e911a90ce328d (patch)
tree785407ea3e991fb4ab05e33e12d9c3fbb6f9371c /prism_compile.c
parent64ab04da6ae15243e1615739f2529f37e532943d (diff)
downloadruby-f80262b14d01a977ce386a5a377e911a90ce328d.tar.gz
[PRISM] Account for nil parent in Call{Operator,And,Or}PathWriteNodes
Prior to this commit, we were not accounting for the case of a nil parent in a CallXPathWriteNode, for example ::A ||= 1. This commit checks if the parent exists, and if not, uses Object as the inferred parent
Diffstat (limited to 'prism_compile.c')
-rw-r--r--prism_compile.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/prism_compile.c b/prism_compile.c
index f6d31e3cdc..7c41f5804b 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -2309,7 +2309,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
LABEL *lfin = NEW_LABEL(lineno);
pm_constant_path_node_t *target = constant_path_and_write_node->target;
- PM_COMPILE_NOT_POPPED(target->parent);
+ if (target->parent) {
+ PM_COMPILE_NOT_POPPED(target->parent);
+ }
+ else {
+ ADD_INSN1(ret, &dummy_line_node, putobject, rb_cObject);
+ }
pm_constant_read_node_t *child = (pm_constant_read_node_t *)target->child;
VALUE child_name = ID2SYM(pm_constant_id_lookup(scope_node, child->name));
@@ -2347,7 +2352,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
LABEL *lfin = NEW_LABEL(lineno);
pm_constant_path_node_t *target = constant_path_or_write_node->target;
- PM_COMPILE_NOT_POPPED(target->parent);
+ if (target->parent) {
+ PM_COMPILE_NOT_POPPED(target->parent);
+ }
+ else {
+ ADD_INSN1(ret, &dummy_line_node, putobject, rb_cObject);
+ }
pm_constant_read_node_t *child = (pm_constant_read_node_t *)target->child;
VALUE child_name = ID2SYM(pm_constant_id_lookup(scope_node, child->name));
@@ -2387,7 +2397,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
pm_constant_path_operator_write_node_t *constant_path_operator_write_node = (pm_constant_path_operator_write_node_t*) node;
pm_constant_path_node_t *target = constant_path_operator_write_node->target;
- PM_COMPILE_NOT_POPPED(target->parent);
+ if (target->parent) {
+ PM_COMPILE_NOT_POPPED(target->parent);
+ }
+ else {
+ ADD_INSN1(ret, &dummy_line_node, putobject, rb_cObject);
+ }
PM_DUP;
ADD_INSN1(ret, &dummy_line_node, putobject, Qtrue);