Implement a flag for extend-like behavior of the `+=` operator for lists

Usage: --incompatible_list_plus_equals=true (the default value is false).
PiperOrigin-RevId: 155084916
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 848498b..a71f656 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
@@ -987,6 +987,73 @@
   }
 
   @Test
+  public void testPlusEqualsOnListCopying() throws Exception {
+    new SkylarkTest("--incompatible_list_plus_equals=false")
+        .setUp(
+            "def func():",
+            "  l1 = [1, 2]",
+            "  l2 = l1",
+            "  l2 += [3, 4]",
+            "  return l1, l2",
+            "lists = str(func())")
+        .testLookup("lists", "([1, 2], [1, 2, 3, 4])");
+  }
+
+  @Test
+  public void testPlusEqualsOnListMutating() throws Exception {
+    new SkylarkTest("--incompatible_list_plus_equals=true")
+        .setUp(
+            "def func():",
+            "  l1 = [1, 2]",
+            "  l2 = l1",
+            "  l2 += [3, 4]",
+            "  return l1, l2",
+            "lists = str(func())")
+        .testLookup("lists", "([1, 2, 3, 4], [1, 2, 3, 4])");
+
+    // The same but with += after an IndexExpression
+    new SkylarkTest("--incompatible_list_plus_equals=true")
+        .setUp(
+            "def func():",
+            "  l = [1, 2]",
+            "  d = {0: l}",
+            "  d[0] += [3, 4]",
+            "  return l, d[0]",
+            "lists = str(func())")
+        .testLookup("lists", "([1, 2, 3, 4], [1, 2, 3, 4])");
+  }
+
+  @Test
+  public void testPlusEqualsOnTuple() throws Exception {
+    new SkylarkTest("--incompatible_list_plus_equals=false")
+        .setUp(
+            "def func():",
+            "  t1 = (1, 2)",
+            "  t2 = t1",
+            "  t2 += (3, 4)",
+            "  return t1, t2",
+            "tuples = func()")
+        .testLookup("tuples", SkylarkList.Tuple.of(
+            SkylarkList.Tuple.of(1, 2),
+            SkylarkList.Tuple.of(1, 2, 3, 4)
+        ));
+
+    // This behavior should remain the same regardless of the incompatible_list_plus_equals flag
+    new SkylarkTest("--incompatible_list_plus_equals=true")
+        .setUp(
+            "def func():",
+            "  t1 = (1, 2)",
+            "  t2 = t1",
+            "  t2 += (3, 4)",
+            "  return t1, t2",
+            "tuples = func()")
+        .testLookup("tuples", SkylarkList.Tuple.of(
+            SkylarkList.Tuple.of(1, 2),
+            SkylarkList.Tuple.of(1, 2, 3, 4)
+        ));
+  }
+
+  @Test
   public void testPlusEqualsOnDict() throws Exception {
     new SkylarkTest().setUp("def func():",
         "  d = {'a' : 1}",