Unify Skylark and BUILD lists

Use SkylarkList everywhere rather than either List or GlobList.
Keep a GlobList underneath a MutableList, where applicable.

--
MOS_MIGRATED_REVID=105864035
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index c753d68..f97c452 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -310,7 +310,7 @@
   public void testCreateSpawnActionBadGenericArg() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
-        "Illegal argument in call to action: list element \"a\" is not of type File",
+        "Illegal argument: expected type File for 'outputs' element but got type string instead",
         "l = ['a', 'b']",
         "ruleContext.action(",
         "  outputs = l,",
@@ -552,7 +552,7 @@
 
   public void testRunfilesBadListGenericType() throws Exception {
     checkErrorContains(
-        "Illegal argument in call to runfiles: list element \"some string\" is not of type File",
+        "Illegal argument: expected type File for 'files' element but got type string instead",
         "ruleContext.runfiles(files = ['some string'])");
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
index b036e5a..85880c7 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
@@ -1,4 +1,4 @@
-// Copyright 2006-2015 Google Inc. All Rights Reserved.
+// Copyright 2006 The Bazel Authors. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventCollector;
 import com.google.devtools.build.lib.packages.CachingPackageLocator;
+import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
+import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
 import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
 import com.google.devtools.build.lib.testutil.Scratch;
 import com.google.devtools.build.lib.vfs.Path;
@@ -32,7 +34,6 @@
 import org.junit.runners.JUnit4;
 
 import java.io.IOException;
-import java.util.Arrays;
 
 /**
  * Unit tests for BuildFileAST.
@@ -78,8 +79,8 @@
     //
     // input1.BUILD contains:
     // x = [1,2,'foo',4] + [1,2, "%s%d" % ('foo', 1)]
-    assertEquals(Arrays.<Object>asList(1, 2, "foo", 4, 1, 2, "foo1"),
-                 env.lookup("x"));
+    assertEquals(new MutableList(Tuple.of(1, 2, "foo", 4, 1, 2, "foo1")),
+        env.lookup("x"));
   }
 
   @Test
@@ -94,7 +95,7 @@
     BuildFileAST buildfile = BuildFileAST.parseBuildFile(buildFile, getEventHandler(), false);
 
     assertFalse(buildfile.exec(env, getEventHandler()));
-    Event e = assertContainsEvent("unsupported operand type(s) for +: 'int' and 'List'");
+    Event e = assertContainsEvent("unsupported operand type(s) for +: 'int' and 'list'");
     assertEquals(4, e.getLocation().getStartLineAndColumn().getLine());
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index 9e9b0c0..3816c4b 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -18,8 +18,9 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
+import com.google.devtools.build.lib.syntax.SkylarkList.Tuple;
 import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
 import com.google.devtools.build.lib.testutil.TestMode;
 
@@ -28,7 +29,6 @@
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -324,15 +324,15 @@
     // list
     Object x = eval("[1,2] + [3,4]");
     assertThat((Iterable<Object>) x).containsExactly(1, 2, 3, 4).inOrder();
-    assertEquals(Arrays.asList(1, 2, 3, 4), x);
+    assertEquals(MutableList.of(env, 1, 2, 3, 4), x);
     assertFalse(EvalUtils.isImmutable(x));
 
     // tuple
     x = eval("(1,2) + (3,4)");
-    assertEquals(Arrays.asList(1, 2, 3, 4), x);
+    assertEquals(Tuple.of(1, 2, 3, 4), x);
     assertTrue(EvalUtils.isImmutable(x));
 
-    checkEvalError("can only concatenate Tuple (not \"List\") to Tuple",
+    checkEvalError("unsupported operand type(s) for +: 'tuple' and 'list'",
         "(1,2) + [3,4]"); // list + tuple
   }
 
@@ -392,8 +392,8 @@
 
   @Test
   public void testListComprehensionsMultipleVariables() throws Exception {
-    newTest().testEval("[x + y for x, y in [(1, 2), (3, 4)]]", "[3, 7]").testEval(
-        "[z + t for (z, t) in [[1, 2], [3, 4]]]", "[3, 7]");
+    newTest().testEval("[x + y for x, y in [(1, 2), (3, 4)]]", "[3, 7]")
+        .testEval("[z + t for (z, t) in [[1, 2], [3, 4]]]", "[3, 7]");
   }
 
   @Test
@@ -510,10 +510,12 @@
   @Test
   public void testListConcatenation() throws Exception {
     newTest()
-        .testStatement("[1, 2] + [3, 4]", Arrays.asList(1, 2, 3, 4))
-        .testStatement("(1, 2) + (3, 4)", ImmutableList.of(1, 2, 3, 4))
-        .testIfExactError("can only concatenate List (not \"Tuple\") to List", "[1, 2] + (3, 4)")
-        .testIfExactError("can only concatenate Tuple (not \"List\") to Tuple", "(1, 2) + [3, 4]");
+        .testStatement("[1, 2] + [3, 4]", MutableList.of(env, 1, 2, 3, 4))
+        .testStatement("(1, 2) + (3, 4)", Tuple.of(1, 2, 3, 4))
+        .testIfExactError("unsupported operand type(s) for +: 'list' and 'tuple'",
+            "[1, 2] + (3, 4)")
+        .testIfExactError("unsupported operand type(s) for +: 'tuple' and 'list'",
+            "(1, 2) + [3, 4]");
   }
 
   @SuppressWarnings("unchecked")
@@ -552,7 +554,7 @@
   public void testListComprehensionOnDictionaryCompositeExpression() throws Exception {
     new BuildTest()
         .setUp("d = {1:'a',2:'b'}", "l = [d[x] for x in d]")
-        .testLookup("l", ImmutableList.of("a", "b"));
+        .testLookup("l", MutableList.of(env, "a", "b"));
   }
 
   @Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index 7c0828b..86e8d8f 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -20,6 +20,7 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.syntax.SkylarkList.MutableList;
 import com.google.devtools.build.lib.syntax.util.EvaluationTestCase;
 
 import org.junit.Before;
@@ -27,8 +28,6 @@
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
-import java.util.Arrays;
-
 /**
  * Tests for MethodLibrary.
  */
@@ -915,9 +914,9 @@
 
   @Test
   public void testEnumerateBadArg() throws Exception {
-    // TODO(bazel-team): unify BUILD List and Skylark list, and get rid of this ugly message.
     new BothModesTest().testIfErrorContains(
-        "expected List or sequence for 'list' while calling enumerate but got string instead: a",
+        "Method enumerate(list: sequence) is not applicable for arguments (string): "
+        + "'list' is string, but should be sequence",
         "enumerate('a')");
   }
 
@@ -925,18 +924,18 @@
   public void testPyListAppend() throws Exception {
     new BuildTest()
         .setUp("FOO = ['a', 'b']", "FOO.append('c')")
-        .testLookup("FOO", Arrays.asList("a", "b", "c"))
+        .testLookup("FOO", MutableList.of(env, "a", "b", "c"))
         .testIfErrorContains(
-            "function 'append' is not defined on object of type 'Tuple'", "(1, 2).append(3)");
+            "function append is not defined on object of type 'tuple'", "(1, 2).append(3)");
   }
 
   @Test
   public void testPyListExtend() throws Exception {
     new BuildTest()
         .setUp("FOO = ['a', 'b']", "FOO.extend(['c', 'd'])")
-        .testLookup("FOO", Arrays.asList("a", "b", "c", "d"))
+        .testLookup("FOO", MutableList.of(env, "a", "b", "c", "d"))
         .testIfErrorContains(
-            "function 'extend' is not defined on object of type 'Tuple'", "(1, 2).extend([3, 4])");
+            "function extend is not defined on object of type 'tuple'", "(1, 2).extend([3, 4])");
   }
 
   @Test
@@ -944,7 +943,7 @@
     new BuildTest()
         .setUp("cc_binary = (['hello.cc'])")
         .testIfErrorContains(
-            "'List' object is not callable",
+            "'list' object is not callable",
             "cc_binary(name = 'hello', srcs=['hello.cc'], malloc = '//base:system_malloc')");
   }
 
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 f956f94..eb0f095 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
@@ -917,7 +917,7 @@
 
   @Test
   public void testListAnTupleConcatenationDoesNotWorkInSkylark() throws Exception {
-    new SkylarkTest().testIfExactError("can only concatenate list (not \"tuple\") to list",
+    new SkylarkTest().testIfExactError("unsupported operand type(s) for +: 'list' and 'tuple'",
         "[1, 2] + (3, 4)");
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
index 7fdff2b..d553464 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkListTest.java
@@ -46,6 +46,7 @@
   @Test
   public void testListEmpty() throws Exception {
     assertThat(eval("8 if [1, 2, 3] else 9")).isEqualTo(8);
+    assertThat(eval("8 if [] else 9")).isEqualTo(9);
   }
 
   @Test