Improve error message when calling a builtin function with wrong type
Error message is simpler and doesn't show the type of all arguments.
RELNOTES: None.
PiperOrigin-RevId: 161187134
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 a76bbc6..85979f4 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
@@ -397,8 +397,8 @@
// only one built-in function.
new BothModesTest()
.testIfExactError(
- "method string.index(sub: string, start: int, end: int or NoneType) is not applicable "
- + "for arguments (int, int, NoneType): 'sub' is 'int', but should be 'string'",
+ "argument 'sub' has type 'int', but should be 'string'\n"
+ + "in call to builtin method string.index(sub, start, end)",
"'test'.index(1)");
}
@@ -422,9 +422,8 @@
+ LINE_SEPARATOR
+ "\t\t\"test\".index(x)"
+ LINE_SEPARATOR
- + "method string.index(sub: string, start: int, end: int or NoneType) "
- + "is not applicable "
- + "for arguments (int, int, NoneType): 'sub' is 'int', but should be 'string'",
+ + "argument 'sub' has type 'int', but should be 'string'\n"
+ + "in call to builtin method string.index(sub, start, end)",
"def foo():",
" bar(1)",
"def bar(x):",
@@ -436,13 +435,10 @@
@Test
public void testBuiltinFunctionErrorMessage() throws Exception {
new BothModesTest()
+ .testIfErrorContains("substring \"z\" not found in \"abc\"", "'abc'.index('z')")
.testIfErrorContains(
- "substring \"z\" not found in \"abc\"",
- "'abc'.index('z')")
- .testIfErrorContains(
- "method string.startswith(sub: string, start: int, end: int or NoneType) is not "
- + "applicable for arguments (int, int, NoneType): 'sub' is 'int', "
- + "but should be 'string'",
+ "argument 'sub' has type 'int', but should be 'string'\n"
+ + "in call to builtin method string.startswith(sub, start, end)",
"'test'.startswith(1)")
.testIfErrorContains(
"expected value of type 'list(object)' for parameter args in dict(), "
@@ -1440,8 +1436,8 @@
.testStatement("hash('skylark')", "skylark".hashCode())
.testStatement("hash('google')", "google".hashCode())
.testIfErrorContains(
- "method hash(value: string) is not applicable for arguments (NoneType): "
- + "'value' is 'NoneType', but should be 'string'",
+ "argument 'value' has type 'NoneType', but should be 'string'\n"
+ + "in call to builtin function hash(value)",
"hash(None)");
}
@@ -1479,8 +1475,8 @@
public void testEnumerateBadArg() throws Exception {
new BothModesTest()
.testIfErrorContains(
- "method enumerate(list: sequence) is not applicable for arguments (string): "
- + "'list' is 'string', but should be 'sequence'",
+ "argument 'list' has type 'string', but should be 'sequence'\n"
+ + "in call to builtin function enumerate(list)",
"enumerate('a')");
}
@@ -1515,8 +1511,8 @@
.testLookup("FOO", MutableList.of(env, "a", "b", "c", "d", "e", "f"))
.testIfErrorContains("type 'tuple' has no method extend(list)", "(1, 2).extend([3, 4])")
.testIfErrorContains(
- "method list.extend(items: sequence) is not applicable for arguments "
- + "(int): 'items' is 'int', but should be 'sequence'",
+ "argument 'items' has type 'int', but should be 'sequence'\n"
+ + "in call to builtin method list.extend(items)",
"[1, 2].extend(3)");
}