diff options
author | Kevin Newton <[email protected]> | 2024-12-26 16:24:26 -0500 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-12-26 17:34:58 -0500 |
commit | c859e15875a8448592d6ab6d503681d454020c29 (patch) | |
tree | 11baae4ba6c370e92263aa46f6db4c72a5d98c26 /prism_compile.c | |
parent | 11c9e4f1ceb90d73e1eac6acbf3434a6f7216044 (diff) |
Handle defined? with call chains with blocks
Ensures we can handle expressions like `defined?(a {}.b)`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12475
Diffstat (limited to 'prism_compile.c')
-rw-r--r-- | prism_compile.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c index bb3d91ffde..1828984baa 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3994,9 +3994,11 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l return; } case PM_CALL_NODE: { +#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE)) + const pm_call_node_t *cast = ((const pm_call_node_t *) node); - if (cast->block != NULL && PM_NODE_TYPE_P(cast->block, PM_BLOCK_NODE)) { + if (BLOCK_P(cast)) { dtype = DEFINED_EXPR; break; } @@ -4016,7 +4018,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l if (cast->receiver) { pm_compile_defined_expr0(iseq, cast->receiver, node_location, ret, popped, scope_node, true, lfinish, true); - if (PM_NODE_TYPE_P(cast->receiver, PM_CALL_NODE)) { + if (PM_NODE_TYPE_P(cast->receiver, PM_CALL_NODE) && !BLOCK_P((const pm_call_node_t *) cast->receiver)) { PUSH_INSNL(ret, location, branchunless, lfinish[2]); const pm_call_node_t *receiver = (const pm_call_node_t *) cast->receiver; @@ -4038,6 +4040,8 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l } return; + +#undef BLOCK_P } case PM_YIELD_NODE: PUSH_INSN(ret, location, putnil); |