From 301dacc8e8f403fb419c675382585a81d2944b5d Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Wed, 30 Mar 2022 12:52:48 -0500 Subject: [PATCH] GROOVY-10556 --- .../core/tests/xform/TypeCheckedTests.java | 20 +++++++++++++++++++ .../org/codehaus/groovy/ast/GenericsType.java | 3 +++ .../org/codehaus/groovy/ast/GenericsType.java | 12 +++++------ .../org/codehaus/groovy/ast/GenericsType.java | 12 +++++------ 4 files changed, 35 insertions(+), 12 deletions(-) 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 ecb92d84a1..b028386684 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 @@ -5560,4 +5560,24 @@ public void testTypeChecked10525() { runConformTest(sources); } + + @Test + public void testTypeChecked10556() { + for (String self : new String[] {"(B) this", "this as B"}) { + //@formatter:off + String[] sources = { + "Main.groovy", + "@groovy.transform.TypeChecked\n" + + "abstract class A,X> {\n" + + " B m() {\n" + + " " + self + "\n" + + " }\n" + + "}\n" + + "(new A(){}).m()\n", + }; + //@formatter:on + + runConformTest(sources); + } + } } diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/GenericsType.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/GenericsType.java index 05f210b09f..6cb1186c54 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/GenericsType.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/GenericsType.java @@ -337,6 +337,9 @@ private boolean checkGenerics(final ClassNode classNode) { */ private boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) { if (classNode==null) return false; + // GRECLIPSE add -- GROOVY-10556: "T" vs "C>" bound + if (classNode.isGenericsPlaceHolder()) return true; + // GRECLIPSE end if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes()==null && classNode.redirect().getGenericsTypes()!=null)) { // if the bound is not using generics, there's nothing to compare with return true; diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/GenericsType.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/GenericsType.java index fc40880c49..8661b879b3 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/GenericsType.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/GenericsType.java @@ -323,13 +323,13 @@ private boolean checkGenerics(final ClassNode classNode) { * @return true if generics are compatible */ private static boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) { - if (classNode == null) { - return false; - } - if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) { - // if the bound is not using generics or the class node is a raw type, there's nothing to compare with + if (classNode == null) return false; + if (bound.getGenericsTypes() == null + || classNode.isGenericsPlaceHolder() // GROOVY-10556: "T" vs "C>" bound + || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) + // if the bound is not using generics or the class node is a raw type, there's nothing to compare return true; - } + if (!classNode.equals(bound)) { // the class nodes are on different types // in this situation, we must choose the correct execution path : either the bound diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/GenericsType.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/GenericsType.java index 9dc69cd881..c83f2eb46e 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/GenericsType.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/GenericsType.java @@ -324,13 +324,13 @@ private boolean checkGenerics(final ClassNode classNode) { * @return true if generics are compatible */ private static boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) { - if (classNode == null) { - return false; - } - if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) { - // if the bound is not using generics or the class node is a raw type, there's nothing to compare with + if (classNode == null) return false; + if (bound.getGenericsTypes() == null + || classNode.isGenericsPlaceHolder() // GROOVY-10556: "T" vs "C>" bound + || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) + // if the bound is not using generics or the class node is a raw type, there's nothing to compare return true; - } + if (!classNode.equals(bound)) { // the class nodes are on different types // in this situation, we must choose the correct execution path : either the bound