From 0eb2a0f9ceb4e648f4e7169bfa7613522c1c1198 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 22 Apr 2021 15:47:59 -0500 Subject: [PATCH] GROOVY-10051 --- .../core/tests/xform/TypeCheckedTests.java | 42 +++++++++++++++++++ .../stc/StaticTypeCheckingSupport.java | 4 ++ .../stc/StaticTypeCheckingSupport.java | 4 ++ .../stc/StaticTypeCheckingSupport.java | 4 ++ 4 files changed, 54 insertions(+) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index 1ead1df4db..41ecdcd1be 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -2247,4 +2247,46 @@ public void testTypeChecked10049() { runConformTest(sources, "42"); } + + @Test + public void testTypeChecked10051() { + //@formatter:off + String[] sources = { + "Main.groovy", + "abstract class State/**/ {\n" + + " def HandleContainer getHandleContainer(key) {\n" + + " }\n" + + "}\n" + + "class HandleContainer {\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 getStrings(State state, List keys) {\n" + + " keys.collectMany { key ->\n" + + " List strings = Collections.emptyList()\n" + + " \n" + + " def container = state.getHandleContainer(key)\n" + // returns HandleContainer not HandleContainer + " 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, "[]"); + } } diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java index 03416f3d29..2e8368b99d 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java @@ -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) { diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java index 7ff1a13be9..ccae921e41 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java @@ -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) { diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java index c5d0d7f821..acbebfc6de 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java @@ -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) {