Skip to content

Commit 9014a5d

Browse files
committed
Bandage ordering detection better
1 parent 7d44af4 commit 9014a5d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/jruby/prism/builder/IRBuilderPrism.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,14 @@ private Operand buildCall(Variable resultArg, CallNode node, RubySymbol name, La
760760

761761
// The receiver has to be built *before* call arguments are built
762762
// to preserve expected code execution order
763-
// FIXME: this always builds with order (lacking containsVariableAssignment() in prism).
763+
boolean preserveOrder = containsVariableAssignment(node.receiver);
764764
Operand receiver;
765765
if (callType == CallType.FUNCTIONAL) {
766766
receiver = buildSelf();
767767
} else if (node.receiver instanceof CallNode && ((CallNode) node.receiver).isSafeNavigation()) {
768-
receiver = buildLazyWithOrder((CallNode) node.receiver, lazyLabel, endLabel, true);
768+
receiver = buildLazyWithOrder((CallNode) node.receiver, lazyLabel, endLabel, preserveOrder);
769769
} else {
770-
receiver = buildWithOrder(node.receiver, true);
770+
receiver = buildWithOrder(node.receiver, preserveOrder);
771771
}
772772

773773
if (node.isSafeNavigation()) addInstr(new BNilInstr(lazyLabel, receiver));
@@ -2510,6 +2510,9 @@ private static Array subArray(Operand[] args, int start, int length) {
25102510
// are just operands so we only need to be aware of these being used within assignments.
25112511
@Override
25122512
protected boolean containsVariableAssignment(Node node) {
2513+
if (node instanceof ParenthesesNode parens) return containsVariableAssignment(parens.body);
2514+
if (node instanceof StatementsNode statements) return containsVariableAssignment(statements.body);
2515+
25132516
if (node instanceof LocalVariableWriteNode ||
25142517
node instanceof LocalVariableOperatorWriteNode ||
25152518
node instanceof LocalVariableAndWriteNode ||

0 commit comments

Comments
 (0)