Skip to content

Commit

Permalink
Support compiling PM_DEFINED_NODE with anonymous rest argument forwar…
Browse files Browse the repository at this point in the history
…ding (* and **)
  • Loading branch information
tompng committed Jan 7, 2025
1 parent 4fbe684 commit 311d399
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 11 additions & 8 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3845,9 +3845,10 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
}
case PM_ASSOC_SPLAT_NODE: {
const pm_assoc_splat_node_t *assoc_splat = (const pm_assoc_splat_node_t *) element;

pm_compile_defined_expr0(iseq, assoc_splat->value, node_location, ret, popped, scope_node, true, lfinish, false);
PUSH_INSNL(ret, location, branchunless, lfinish[1]);
if (assoc_splat->value != NULL) {
pm_compile_defined_expr0(iseq, assoc_splat->value, node_location, ret, popped, scope_node, true, lfinish, false);
PUSH_INSNL(ret, location, branchunless, lfinish[1]);
}

break;
}
Expand All @@ -3862,13 +3863,15 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
}
case PM_SPLAT_NODE: {
const pm_splat_node_t *cast = (const pm_splat_node_t *) node;
pm_compile_defined_expr0(iseq, cast->expression, node_location, ret, popped, scope_node, in_condition, lfinish, false);
if (cast->expression != NULL) {
pm_compile_defined_expr0(iseq, cast->expression, node_location, ret, popped, scope_node, in_condition, lfinish, false);

if (!lfinish[1]) {
lfinish[1] = NEW_LABEL(location.line);
}
if (!lfinish[1]) {
lfinish[1] = NEW_LABEL(location.line);
}

PUSH_INSNL(ret, location, branchunless, lfinish[1]);
PUSH_INSNL(ret, location, branchunless, lfinish[1]);
}
dtype = DEFINED_EXPR;
break;
}
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def self.m1; defined?(return) end
assert_prism_eval("defined?((alias $a $b))")
assert_prism_eval("defined?(!(a..b))")
assert_prism_eval("def f(...); defined?(p(...)); end")
assert_prism_eval("def f(*, **, &); defined?(p(*, **, &)); end")
assert_prism_eval("def f(*, **, &); defined?([*, **]); end")
assert_prism_eval("defined?(!/foo/)")
assert_prism_eval('defined?(!/#{1}/)')
assert_prism_eval("defined?((END{}))")
Expand Down

0 comments on commit 311d399

Please sign in to comment.