Skip to content

Commit db118f9

Browse files
committed
writing to a cell in a class scope should still write the value to the namespace also
1 parent 14df767 commit db118f9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/ReadClassAttributeNode.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.graal.python.nodes.expression.ExpressionNode;
4848
import com.oracle.graal.python.nodes.frame.ReadLocalNode;
4949
import com.oracle.graal.python.nodes.frame.ReadNode;
50+
import com.oracle.graal.python.nodes.frame.WriteNode;
5051
import com.oracle.graal.python.nodes.statement.StatementNode;
5152
import com.oracle.graal.python.nodes.subscript.GetItemNode;
5253
import com.oracle.graal.python.runtime.exception.PException;
@@ -94,14 +95,12 @@ public StatementNode makeDeleteNode() {
9495

9596
@Override
9697
public StatementNode makeWriteNode(ExpressionNode rhs) {
97-
ExpressionNode right = rhs;
9898
// freevars pass through the special Class scope
9999
if (readCellLocal != null && !isFreeVar) {
100-
// TODO (tfel): Is this what's intended?
101-
return ((ReadNode) readCellLocal).makeWriteNode(rhs);
100+
return new WriteClassAttributeCellNode((ReadNode) readCellLocal, (ReadNode) getNsItem, rhs);
102101
} else {
103102
// assignments always got to the innermost scope
104-
return ((ReadNode) getNsItem).makeWriteNode(right);
103+
return ((ReadNode) getNsItem).makeWriteNode(rhs);
105104
}
106105
}
107106

@@ -132,4 +131,31 @@ Object read(VirtualFrame frame,
132131
return readGlobal.execute(frame);
133132
}
134133
}
134+
135+
private static class WriteClassAttributeCellNode extends StatementNode implements WriteNode {
136+
@Child private WriteNode writeCellLocal;
137+
@Child private WriteNode writeNsItem;
138+
@Child private ExpressionNode right;
139+
140+
WriteClassAttributeCellNode(ReadNode readCellLocal, ReadNode getNsItem, ExpressionNode rhs) {
141+
writeCellLocal = (WriteNode) readCellLocal.makeWriteNode(null);
142+
writeNsItem = (WriteNode) getNsItem.makeWriteNode(null);
143+
right = rhs;
144+
}
145+
146+
public ExpressionNode getRhs() {
147+
return right;
148+
}
149+
150+
public void doWrite(VirtualFrame frame, Object value) {
151+
writeCellLocal.doWrite(frame, value);
152+
writeNsItem.doWrite(frame, value);
153+
}
154+
155+
@Override
156+
public void executeVoid(VirtualFrame frame) {
157+
Object value = right.execute(frame);
158+
doWrite(frame, value);
159+
}
160+
}
135161
}

0 commit comments

Comments
 (0)