Cleanup Skylark types some more
Clarify the criterion for being a valid Skylark value;
stop claiming immutability is "the" criterion when Skylark now has mutable values;
stop relying on a reflection with a magic list (this also fixes the SkylarkShell build).
Clarify the criterion for determining immutable types when making a SkylarkNestedSet.
Clarify and use the criterion for being a valid Skylark dict key.
--
MOS_MIGRATED_REVID=103313934
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 8668f50..2ebd7df 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
@@ -52,6 +52,11 @@
return new SkylarkTest();
}
+ static class Bad {
+ Bad () {
+ }
+ }
+
@SkylarkModule(name = "Mock", doc = "")
static class Mock {
@SkylarkCallable(doc = "")
@@ -64,8 +69,8 @@
}
public void value() {}
@SkylarkCallable(doc = "")
- public Mock returnMutable() {
- return new Mock();
+ public Bad returnBad() {
+ return new Bad();
}
@SkylarkCallable(name = "struct_field", doc = "", structField = true)
public String structField() {
@@ -305,6 +310,13 @@
}
@Test
+ public void testBadDictKey() throws Exception {
+ new SkylarkTest().testIfErrorContains(
+ "unhashable type: 'list'",
+ "{ [1, 2]: [3, 4] }");
+ }
+
+ @Test
public void testForLoopReuseVariable() throws Exception {
new SkylarkTest().setUp("def foo():",
" s = ''",
@@ -594,8 +606,8 @@
new SkylarkTest()
.update("mock", new Mock())
.testIfExactError(
- "Method 'return_mutable' returns a mutable object (type of Mock)",
- "mock.return_mutable()");
+ "Method 'return_bad' returns an object of invalid type Bad",
+ "mock.return_bad()");
}
@Test
@@ -944,7 +956,7 @@
"is_empty",
"nullfunc_failing",
"nullfunc_working",
- "return_mutable",
+ "return_bad",
"string",
"string_list",
"struct_field",