Skip to content

Commit

Permalink
GROOVY-10010
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 5, 2021
1 parent d58fda3 commit 47e107e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2011,4 +2011,62 @@ public void testTypeChecked9998b() {

runConformTest(sources, "null");
}

@Test
public void testTypeChecked10010() {
//@formatter:off
String[] sources = {
"Main.groovy",
"void m(List<String> list) { }\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" def bar = 123\n" +
" m([\"foo\",\"$bar\"])\n" +
" List<String> list = [\"foo\",\"$bar\"]\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 5)\n" +
"\tm([\"foo\",\"$bar\"])\n" +
"\t^^^^^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - You are trying to use a GString in place of a String in a type which explicitly declares accepting String. Make sure to call toString() on all GString values.\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 6)\n" +
"\tList<String> list = [\"foo\",\"$bar\"]\n" +
"\t ^^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - You are trying to use a GString in place of a String in a type which explicitly declares accepting String. Make sure to call toString() on all GString values.\n" +
"----------\n");
}

@Test
public void testTypeChecked10010a() {
//@formatter:off
String[] sources = {
"Main.groovy",
"void m(Map<?,String> map) { }\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" def bar = 123\n" +
" m([x:\"foo\",y:\"$bar\"])\n" +
" Map<String,String> map = [x:\"foo\",y:\"$bar\"]\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 5)\n" +
"\tm([x:\"foo\",y:\"$bar\"])\n" +
"\t^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - You are trying to use a GString in place of a String in a type which explicitly declares accepting String. Make sure to call toString() on all GString values.\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 6)\n" +
"\tMap<String,String> map = [x:\"foo\",y:\"$bar\"]\n" +
"\t ^^^^^^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - You are trying to use a GString in place of a String in a type which explicitly declares accepting String. Make sure to call toString() on all GString values.\n" +
"----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ private boolean compareGenericsWithBound(final ClassNode classNode, final ClassN
if (!match) break;
}
}
/* GRECLIPSE edit -- GROOVY-10010
return match;
*/
continue;
// GRECLIPSE end
} else if (classNodePlaceholders.containsKey(name)) {
redirectBoundType = classNodePlaceholders.get(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6267,6 +6267,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNo
final Parameter parameter = parameters[i];
ClassNode type = parameter.getType();
ptypes[i] = fullyResolveType(type, classGTs);
// GRECLIPSE add -- GROOVY-10010
if (i < arguments.length && hasGStringStringError(ptypes[i], arguments[i], location)) {
return false;
}
// GRECLIPSE end
}
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
toMethodParametersString(candidateMethod.getName(), ptypes) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,11 @@ private static boolean compareGenericsWithBound(final ClassNode classNode, final
if (!match) break;
}
}
/* GRECLIPSE edit -- GROOVY-10010
return match;
*/
continue;
// GRECLIPSE end
}
}
match = redirectBoundType.isCompatibleWith(classNodeType.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6031,6 +6031,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(final ClassNode receiver, f
ClassNode[] paramTypes = new ClassNode[parameters.length];
for (int i = 0, n = parameters.length; i < n; i += 1) {
paramTypes[i] = fullyResolveType(parameters[i].getType(), classGTs);
// GRECLIPSE add -- GROOVY-10010
if (i < arguments.length && hasGStringStringError(paramTypes[i], arguments[i], location)) {
return false;
}
// GRECLIPSE end
}
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
toMethodParametersString(candidateMethod.getName(), paramTypes) + " with arguments " + formatArgumentList(arguments), location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ private static boolean compareGenericsWithBound(final ClassNode classNode, final
if (!match) break;
}
}
/* GRECLIPSE edit -- GROOVY-10010
return match;
*/
continue;
// GRECLIPSE end
}
}
match = redirectBoundType.isCompatibleWith(classNodeType.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5979,6 +5979,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(final ClassNode receiver, f
ClassNode[] paramTypes = new ClassNode[parameters.length];
for (int i = 0, n = parameters.length; i < n; i += 1) {
paramTypes[i] = fullyResolveType(parameters[i].getType(), classGTs);
// GRECLIPSE add -- GROOVY-10010
if (i < arguments.length && hasGStringStringError(paramTypes[i], arguments[i], location)) {
return false;
}
// GRECLIPSE end
}
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
toMethodParametersString(candidateMethod.getName(), paramTypes) + " with arguments " + formatArgumentList(arguments), location);
Expand Down

0 comments on commit 47e107e

Please sign in to comment.