Skip to content

Commit 0eb2a0f

Browse files
committed
GROOVY-10051
1 parent b8b8cbe commit 0eb2a0f

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -2247,4 +2247,46 @@ public void testTypeChecked10049() {
22472247

22482248
runConformTest(sources, "42");
22492249
}
2250+
2251+
@Test
2252+
public void testTypeChecked10051() {
2253+
//@formatter:off
2254+
String[] sources = {
2255+
"Main.groovy",
2256+
"abstract class State/*<H extends Handle>*/ {\n" +
2257+
" def <T extends Handle> HandleContainer<T> getHandleContainer(key) {\n" +
2258+
" }\n" +
2259+
"}\n" +
2260+
"class HandleContainer<H extends Handle> {\n" +
2261+
" H handle\n" +
2262+
"}\n" +
2263+
"interface Handle {\n" +
2264+
" Result getResult()\n" +
2265+
"}\n" +
2266+
"class Result {\n" +
2267+
" int itemCount\n" +
2268+
" String[] items\n" +
2269+
"}\n" +
2270+
"@groovy.transform.TypeChecked\n" +
2271+
"List<String> getStrings(State state, List<?> keys) {\n" +
2272+
" keys.collectMany { key ->\n" +
2273+
" List<String> strings = Collections.emptyList()\n" +
2274+
" \n" +
2275+
" def container = state.getHandleContainer(key)\n" + // returns HandleContainer<Object> not HandleContainer<Handle>
2276+
" if (container != null) {\n" +
2277+
" def result = container.handle.result\n" +
2278+
" if (result != null && result.itemCount > 0) {\n" +
2279+
" strings = Arrays.asList(result.items)\n" +
2280+
" }\n" +
2281+
" }\n" +
2282+
" \n" +
2283+
" strings\n" +
2284+
" }\n" +
2285+
"}\n" +
2286+
"print getStrings(null,[])\n",
2287+
};
2288+
//@formatter:on
2289+
2290+
runConformTest(sources, "[]");
2291+
}
22502292
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,11 @@ private static ClassNode extractType(GenericsType gt) {
18171817
}
18181818
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
18191819
// the actual bounds and not the name of the placeholder.
1820+
/* GRECLIPSE edit -- GROOVY-10051
18201821
ClassNode replacementType = OBJECT_TYPE;
1822+
*/
1823+
ClassNode replacementType = gt.getType().redirect();
1824+
// GRECLIPSE end
18211825
if (gt.getType().getGenericsTypes() != null) {
18221826
GenericsType realGt = gt.getType().getGenericsTypes()[0];
18231827
if (realGt.getLowerBound() != null) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,11 @@ private static ClassNode extractType(final GenericsType gt) {
17311731
}
17321732
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
17331733
// the actual bounds and not the name of the placeholder.
1734+
/* GRECLIPSE edit -- GROOVY-10051
17341735
ClassNode replacementType = OBJECT_TYPE;
1736+
*/
1737+
ClassNode replacementType = gt.getType().redirect();
1738+
// GRECLIPSE end
17351739
if (gt.getType().getGenericsTypes() != null) {
17361740
GenericsType realGt = gt.getType().getGenericsTypes()[0];
17371741
if (realGt.getLowerBound() != null) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,11 @@ private static ClassNode extractType(final GenericsType gt) {
16731673
}
16741674
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
16751675
// the actual bounds and not the name of the placeholder.
1676+
/* GRECLIPSE edit -- GROOVY-10051
16761677
ClassNode replacementType = OBJECT_TYPE;
1678+
*/
1679+
ClassNode replacementType = gt.getType().redirect();
1680+
// GRECLIPSE end
16771681
if (gt.getType().getGenericsTypes() != null) {
16781682
GenericsType realGt = gt.getType().getGenericsTypes()[0];
16791683
if (realGt.getLowerBound() != null) {

0 commit comments

Comments
 (0)