Throw a static error when lvalue of an augmented assignment is a list.
RELNOTES:
When the lvalue of an augmented assignment is a list, we now throw an error
before evaluating the code (e.g. `a, b += 2, 3`).
PiperOrigin-RevId: 165906611
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
index 4415a85..6f5eb9c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java
@@ -158,6 +158,16 @@
super.visit(node);
}
+ @Override
+ public void visit(AugmentedAssignmentStatement node) {
+ if (node.getLValue().getExpression() instanceof ListLiteral) {
+ throw new ValidationException(
+ node.getLocation(), "cannot perform augmented assignment on a list or tuple expression");
+ }
+ // Other bad cases are handled when visiting the LValue node.
+ super.visit(node);
+ }
+
/** Returns true if the current block is the top level i.e. has no parent. */
private boolean isTopLevel() {
return block.parent == null;