Augmented assignments don't evaluate lhs multiple times

--
PiperOrigin-RevId: 148092963
MOS_MIGRATED_REVID=148092963
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 0a701e0..6353c12 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -909,6 +909,49 @@
   }
 
   @Test
+  public void testAugmentedAssignmentHasNoSideEffects() throws Exception {
+    new SkylarkTest().setUp(
+        "counter = [0]",
+        "value = [1, 2]",
+        "",
+        "def f():",
+        "  counter[0] = counter[0] + 1",
+        "  return value",
+        "",
+        "f()[1] += 1")  // `f()` should be called only once here
+        .testLookup("counter", MutableList.of(env, 1));
+  }
+
+  @Test
+  public void testAugmentedAssignmentNotAllowedForListLiterals() throws Exception {
+    new SkylarkTest().testIfErrorContains("Cannot perform augment assignment on a list literal",
+        "def f(a, b):",
+        "  [a, b] += []",
+        "f(1, 2)");
+  }
+
+  @Test
+  public void testAssignmentEvaluationOrder() throws Exception {
+    new SkylarkTest().setUp(
+        "ordinary = []",
+        "augmented = []",
+        "value = [1, 2]",
+        "",
+        "def f(record):",
+        "  record.append('f')",
+        "  return value",
+        "",
+        "def g(record):",
+        "  record.append('g')",
+        "  return value",
+        "",
+        "f(ordinary)[0] = g(ordinary)[1]",
+        "f(augmented)[0] += g(augmented)[1]")
+        .testLookup("ordinary", MutableList.of(env, "g", "f"))    // This order is consistent
+        .testLookup("augmented", MutableList.of(env, "f", "g"));  // with Python
+  }
+
+  @Test
   public void testStaticDirectJavaCall() throws Exception {
     new SkylarkTest().update("Mock", Mock.class).setUp("val = Mock.value_of('8')")
         .testLookup("val", 8);