Skip to content

Commit

Permalink
GROOVY-10051
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 22, 2021
1 parent b8b8cbe commit 0eb2a0f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2247,4 +2247,46 @@ public void testTypeChecked10049() {

runConformTest(sources, "42");
}

@Test
public void testTypeChecked10051() {
//@formatter:off
String[] sources = {
"Main.groovy",
"abstract class State/*<H extends Handle>*/ {\n" +
" def <T extends Handle> HandleContainer<T> getHandleContainer(key) {\n" +
" }\n" +
"}\n" +
"class HandleContainer<H extends Handle> {\n" +
" H handle\n" +
"}\n" +
"interface Handle {\n" +
" Result getResult()\n" +
"}\n" +
"class Result {\n" +
" int itemCount\n" +
" String[] items\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"List<String> getStrings(State state, List<?> keys) {\n" +
" keys.collectMany { key ->\n" +
" List<String> strings = Collections.emptyList()\n" +
" \n" +
" def container = state.getHandleContainer(key)\n" + // returns HandleContainer<Object> not HandleContainer<Handle>
" if (container != null) {\n" +
" def result = container.handle.result\n" +
" if (result != null && result.itemCount > 0) {\n" +
" strings = Arrays.asList(result.items)\n" +
" }\n" +
" }\n" +
" \n" +
" strings\n" +
" }\n" +
"}\n" +
"print getStrings(null,[])\n",
};
//@formatter:on

runConformTest(sources, "[]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,11 @@ private static ClassNode extractType(GenericsType gt) {
}
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
// the actual bounds and not the name of the placeholder.
/* GRECLIPSE edit -- GROOVY-10051
ClassNode replacementType = OBJECT_TYPE;
*/
ClassNode replacementType = gt.getType().redirect();
// GRECLIPSE end
if (gt.getType().getGenericsTypes() != null) {
GenericsType realGt = gt.getType().getGenericsTypes()[0];
if (realGt.getLowerBound() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,11 @@ private static ClassNode extractType(final GenericsType gt) {
}
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
// the actual bounds and not the name of the placeholder.
/* GRECLIPSE edit -- GROOVY-10051
ClassNode replacementType = OBJECT_TYPE;
*/
ClassNode replacementType = gt.getType().redirect();
// GRECLIPSE end
if (gt.getType().getGenericsTypes() != null) {
GenericsType realGt = gt.getType().getGenericsTypes()[0];
if (realGt.getLowerBound() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,11 @@ private static ClassNode extractType(final GenericsType gt) {
}
// For a placeholder, a type based on the generics type is used for the compatibility check, to match on
// the actual bounds and not the name of the placeholder.
/* GRECLIPSE edit -- GROOVY-10051
ClassNode replacementType = OBJECT_TYPE;
*/
ClassNode replacementType = gt.getType().redirect();
// GRECLIPSE end
if (gt.getType().getGenericsTypes() != null) {
GenericsType realGt = gt.getType().getGenericsTypes()[0];
if (realGt.getLowerBound() != null) {
Expand Down

0 comments on commit 0eb2a0f

Please sign in to comment.