Skip to content

Commit

Permalink
[PRISM] Fix defined? for chained calls
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 16, 2024
1 parent d6b6e14 commit 0520e96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,8 +2607,10 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *co
pm_compile_defined_expr0(iseq, call_node->receiver, ret, src, popped, scope_node, dummy_line_node, lineno, true, lfinish, true);
if (PM_NODE_TYPE_P(call_node->receiver, PM_CALL_NODE)) {
ADD_INSNL(ret, &dummy_line_node, branchunless, lfinish[2]);
ID method_id = pm_constant_id_lookup(scope_node, call_node->name);
pm_compile_call(iseq, (const pm_call_node_t *)call_node->receiver, ret, src, popped, scope_node, method_id, NULL);

const pm_call_node_t *receiver = (const pm_call_node_t *)call_node->receiver;
ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
pm_compile_call(iseq, receiver, ret, src, popped, scope_node, method_id, NULL);
}
else {
ADD_INSNL(ret, &dummy_line_node, branchunless, lfinish[1]);
Expand Down
9 changes: 9 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ def test_DefinedNode

assert_prism_eval("defined?(a(itself))")
assert_prism_eval("defined?(itself(itself))")

# Method chain on a constant
assert_prism_eval(<<~RUBY)
class PrismDefinedNode
def m1; end
end
defined?(PrismDefinedNode.new.m1)
RUBY
end

def test_GlobalVariableReadNode
Expand Down

0 comments on commit 0520e96

Please sign in to comment.