Skip to content

Commit 47e107e

Browse files
committed
GROOVY-10010
1 parent d58fda3 commit 47e107e

File tree

7 files changed

+85
-0
lines changed

7 files changed

+85
-0
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+58
Original file line numberDiff line numberDiff line change
@@ -2011,4 +2011,62 @@ public void testTypeChecked9998b() {
20112011

20122012
runConformTest(sources, "null");
20132013
}
2014+
2015+
@Test
2016+
public void testTypeChecked10010() {
2017+
//@formatter:off
2018+
String[] sources = {
2019+
"Main.groovy",
2020+
"void m(List<String> list) { }\n" +
2021+
"@groovy.transform.TypeChecked\n" +
2022+
"void test() {\n" +
2023+
" def bar = 123\n" +
2024+
" m([\"foo\",\"$bar\"])\n" +
2025+
" List<String> list = [\"foo\",\"$bar\"]\n" +
2026+
"}\n",
2027+
};
2028+
//@formatter:on
2029+
2030+
runNegativeTest(sources,
2031+
"----------\n" +
2032+
"1. ERROR in Main.groovy (at line 5)\n" +
2033+
"\tm([\"foo\",\"$bar\"])\n" +
2034+
"\t^^^^^^^^^^^^^^^^^\n" +
2035+
"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" +
2036+
"----------\n" +
2037+
"2. ERROR in Main.groovy (at line 6)\n" +
2038+
"\tList<String> list = [\"foo\",\"$bar\"]\n" +
2039+
"\t ^^^^^^^^^^^^^^\n" +
2040+
"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" +
2041+
"----------\n");
2042+
}
2043+
2044+
@Test
2045+
public void testTypeChecked10010a() {
2046+
//@formatter:off
2047+
String[] sources = {
2048+
"Main.groovy",
2049+
"void m(Map<?,String> map) { }\n" +
2050+
"@groovy.transform.TypeChecked\n" +
2051+
"void test() {\n" +
2052+
" def bar = 123\n" +
2053+
" m([x:\"foo\",y:\"$bar\"])\n" +
2054+
" Map<String,String> map = [x:\"foo\",y:\"$bar\"]\n" +
2055+
"}\n",
2056+
};
2057+
//@formatter:on
2058+
2059+
runNegativeTest(sources,
2060+
"----------\n" +
2061+
"1. ERROR in Main.groovy (at line 5)\n" +
2062+
"\tm([x:\"foo\",y:\"$bar\"])\n" +
2063+
"\t^^^^^^^^^^^^^^^^^^^^^\n" +
2064+
"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" +
2065+
"----------\n" +
2066+
"2. ERROR in Main.groovy (at line 6)\n" +
2067+
"\tMap<String,String> map = [x:\"foo\",y:\"$bar\"]\n" +
2068+
"\t ^^^^^^^^^^^^^^^^^^\n" +
2069+
"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" +
2070+
"----------\n");
2071+
}
20142072
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/GenericsType.java

+4
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ private boolean compareGenericsWithBound(final ClassNode classNode, final ClassN
531531
if (!match) break;
532532
}
533533
}
534+
/* GRECLIPSE edit -- GROOVY-10010
534535
return match;
536+
*/
537+
continue;
538+
// GRECLIPSE end
535539
} else if (classNodePlaceholders.containsKey(name)) {
536540
redirectBoundType = classNodePlaceholders.get(name);
537541
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -6267,6 +6267,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNo
62676267
final Parameter parameter = parameters[i];
62686268
ClassNode type = parameter.getType();
62696269
ptypes[i] = fullyResolveType(type, classGTs);
6270+
// GRECLIPSE add -- GROOVY-10010
6271+
if (i < arguments.length && hasGStringStringError(ptypes[i], arguments[i], location)) {
6272+
return false;
6273+
}
6274+
// GRECLIPSE end
62706275
}
62716276
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
62726277
toMethodParametersString(candidateMethod.getName(), ptypes) +

base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/GenericsType.java

+4
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ private static boolean compareGenericsWithBound(final ClassNode classNode, final
490490
if (!match) break;
491491
}
492492
}
493+
/* GRECLIPSE edit -- GROOVY-10010
493494
return match;
495+
*/
496+
continue;
497+
// GRECLIPSE end
494498
}
495499
}
496500
match = redirectBoundType.isCompatibleWith(classNodeType.getType());

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -6031,6 +6031,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(final ClassNode receiver, f
60316031
ClassNode[] paramTypes = new ClassNode[parameters.length];
60326032
for (int i = 0, n = parameters.length; i < n; i += 1) {
60336033
paramTypes[i] = fullyResolveType(parameters[i].getType(), classGTs);
6034+
// GRECLIPSE add -- GROOVY-10010
6035+
if (i < arguments.length && hasGStringStringError(paramTypes[i], arguments[i], location)) {
6036+
return false;
6037+
}
6038+
// GRECLIPSE end
60346039
}
60356040
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
60366041
toMethodParametersString(candidateMethod.getName(), paramTypes) + " with arguments " + formatArgumentList(arguments), location);

base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/GenericsType.java

+4
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ private static boolean compareGenericsWithBound(final ClassNode classNode, final
495495
if (!match) break;
496496
}
497497
}
498+
/* GRECLIPSE edit -- GROOVY-10010
498499
return match;
500+
*/
501+
continue;
502+
// GRECLIPSE end
499503
}
500504
}
501505
match = redirectBoundType.isCompatibleWith(classNodeType.getType());

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+5
Original file line numberDiff line numberDiff line change
@@ -5979,6 +5979,11 @@ protected boolean typeCheckMethodsWithGenericsOrFail(final ClassNode receiver, f
59795979
ClassNode[] paramTypes = new ClassNode[parameters.length];
59805980
for (int i = 0, n = parameters.length; i < n; i += 1) {
59815981
paramTypes[i] = fullyResolveType(parameters[i].getType(), classGTs);
5982+
// GRECLIPSE add -- GROOVY-10010
5983+
if (i < arguments.length && hasGStringStringError(paramTypes[i], arguments[i], location)) {
5984+
return false;
5985+
}
5986+
// GRECLIPSE end
59825987
}
59835988
addStaticTypeError("Cannot call " + toMethodGenericTypesString(candidateMethod) + receiver.toString(false) + "#" +
59845989
toMethodParametersString(candidateMethod.getName(), paramTypes) + " with arguments " + formatArgumentList(arguments), location);

0 commit comments

Comments
 (0)