Skip to content

Commit e3f182d

Browse files
committed
Fix op asgn of const capturing side-effects
1 parent 6de0cb7 commit e3f182d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,17 @@ private Operand buildConstantPathAndWrite(ConstantPathAndWriteNode node) {
848848
}
849849

850850
private Operand buildConstantPathOperatorWrite(ConstantPathOperatorWriteNode node) {
851-
return buildOpAsgnConstDecl(node.target, node.value, node.binary_operator);
851+
var path = node.target;
852+
853+
if (path.parent == null) {
854+
return buildOpAsgnConstDecl(node.target, node.value, node.binary_operator);
855+
} else {
856+
Operand parent = build(path.parent);
857+
Operand lhs = searchModuleForConst(temp(), parent, path.name);
858+
Operand rhs = build(node.value);
859+
Variable result = call(temp(), lhs, node.binary_operator, rhs);
860+
return copy(temp(), putConstant(parent, path.name, result));
861+
}
852862
}
853863

854864
private Operand buildConstantPathOrWrite(ConstantPathOrWriteNode node) {

0 commit comments

Comments
 (0)