Skip to content

Commit 67ae57c

Browse files
committed
Fix defined_expr compilation of method call with parenthesized receiver
1 parent 31905d9 commit 67ae57c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

prism_compile.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
37553755
const pm_node_list_t *arguments = &cast->arguments;
37563756
for (size_t idx = 0; idx < arguments->size; idx++) {
37573757
const pm_node_t *argument = arguments->nodes[idx];
3758-
pm_compile_defined_expr0(iseq, argument, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
3758+
pm_compile_defined_expr0(iseq, argument, node_location, ret, popped, scope_node, in_condition, lfinish, false);
37593759

37603760
if (!lfinish[1]) {
37613761
lfinish[1] = NEW_LABEL(location.line);
@@ -3778,7 +3778,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
37783778
else if (PM_NODE_TYPE_P(cast->body, PM_STATEMENTS_NODE) && ((const pm_statements_node_t *) cast->body)->body.size == 1) {
37793779
// If we have a parentheses node that is wrapping a single statement
37803780
// then we want to recurse down to that statement and compile it.
3781-
pm_compile_defined_expr0(iseq, ((const pm_statements_node_t *) cast->body)->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
3781+
pm_compile_defined_expr0(iseq, ((const pm_statements_node_t *) cast->body)->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish, false);
37823782
return;
37833783
}
37843784
else {
@@ -3874,7 +3874,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
38743874
}
38753875
case PM_IMPLICIT_NODE: {
38763876
const pm_implicit_node_t *cast = (const pm_implicit_node_t *) node;
3877-
pm_compile_defined_expr0(iseq, cast->value, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
3877+
pm_compile_defined_expr0(iseq, cast->value, node_location, ret, popped, scope_node, in_condition, lfinish, false);
38783878
return;
38793879
}
38803880
case PM_AND_NODE:
@@ -4018,16 +4018,16 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
40184018
}
40194019

40204020
if (cast->receiver) {
4021-
pm_compile_defined_expr0(iseq, cast->receiver, node_location, ret, popped, scope_node, true, lfinish, true);
4022-
40234021
if (PM_NODE_TYPE_P(cast->receiver, PM_CALL_NODE) && !BLOCK_P((const pm_call_node_t *) cast->receiver)) {
4022+
pm_compile_defined_expr0(iseq, cast->receiver, node_location, ret, popped, scope_node, true, lfinish, true);
40244023
PUSH_INSNL(ret, location, branchunless, lfinish[2]);
40254024

40264025
const pm_call_node_t *receiver = (const pm_call_node_t *) cast->receiver;
40274026
ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
40284027
pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
40294028
}
40304029
else {
4030+
pm_compile_defined_expr0(iseq, cast->receiver, node_location, ret, popped, scope_node, true, lfinish, false);
40314031
PUSH_INSNL(ret, location, branchunless, lfinish[1]);
40324032
PM_COMPILE(cast->receiver);
40334033
}
@@ -4106,7 +4106,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
41064106
}
41074107

41084108
static void
4109-
pm_defined_expr(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_location_t *node_location, LINK_ANCHOR *const ret, bool popped, pm_scope_node_t *scope_node, bool in_condition, LABEL **lfinish, bool explicit_receiver)
4109+
pm_defined_expr(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_location_t *node_location, LINK_ANCHOR *const ret, bool popped, pm_scope_node_t *scope_node, bool in_condition, LABEL **lfinish)
41104110
{
41114111
LINK_ELEMENT *lcur = ret->last;
41124112
pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish, false);
@@ -4147,7 +4147,7 @@ pm_compile_defined_expr(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_lo
41474147
lfinish[2] = 0;
41484148

41494149
if (!popped) {
4150-
pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish, false);
4150+
pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
41514151
}
41524152

41534153
if (lfinish[1]) {

test/ruby/test_compile_prism.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ def test_DefinedNode
210210
# method chain with a block on the inside
211211
assert_prism_eval("defined?(itself { 1 }.itself)")
212212

213+
# method chain with parenthesized receiver
214+
assert_prism_eval("defined?((itself).itself)")
215+
213216
# Method chain on a constant
214217
assert_prism_eval(<<~RUBY)
215218
class PrismDefinedNode

0 commit comments

Comments
 (0)