You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/06/07 19:02:10 UTC

[groovy] branch master updated: GROOVY-10125: fix for type parameter cycle false positive

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new f48bb09  GROOVY-10125: fix for type parameter cycle false positive
f48bb09 is described below

commit f48bb0938efd7959accc254a013c55dd0fa7374f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Jun 7 14:01:45 2021 -0500

    GROOVY-10125: fix for type parameter cycle false positive
---
 .../codehaus/groovy/control/ResolveVisitor.java    |  4 ++--
 src/test/groovy/bugs/Groovy10113.groovy            | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 16440cf..1f42535 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1490,7 +1490,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
             for (GenericsType gt : node.getGenericsTypes()) {
                 if (gt != null && gt.getUpperBounds() != null) {
                     for (ClassNode variant : gt.getUpperBounds()) {
-                        if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(gt.getType().redirect(), variant);
+                        if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(variant, gt.getType());
                     }
                 }
             }
@@ -1505,7 +1505,7 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
 
     private void checkCyclicInheritance(final ClassNode node, final ClassNode type) {
         if (type.redirect() == node || type.getOuterClasses().contains(node)) {
-            addError("Cycle detected: the type " + node.getName() + " cannot extend/implement itself or one of its own member types", type);
+            addError("Cycle detected: the type " + node.getUnresolvedName() + " cannot extend/implement itself or one of its own member types", type);
         } else if (type != ClassHelper.OBJECT_TYPE) {
             Set<ClassNode> done = new HashSet<>();
             done.add(ClassHelper.OBJECT_TYPE);
diff --git a/src/test/groovy/bugs/Groovy10113.groovy b/src/test/groovy/bugs/Groovy10113.groovy
index 142f2f3..e2f08ff 100644
--- a/src/test/groovy/bugs/Groovy10113.groovy
+++ b/src/test/groovy/bugs/Groovy10113.groovy
@@ -20,12 +20,13 @@ package groovy.bugs
 
 import org.junit.Test
 
+import static groovy.test.GroovyAssert.assertScript
 import static groovy.test.GroovyAssert.shouldFail
 
 final class Groovy10113 {
 
     @Test
-    void testTypeParamCycle() {
+    void testTypeParamCycle1() {
         def err = shouldFail '''
             class C<T extends T> {
             }
@@ -34,6 +35,25 @@ final class Groovy10113 {
     }
 
     @Test
+    void testTypeParamCycle2() {
+        def err = shouldFail '''
+            class C<T extends U, U extends T> {
+            }
+        '''
+        // TODO:                 ^ error is here but refers to T; is there a way to move the error or improve it
+        assert err =~ /Cycle detected: the type T cannot extend.implement itself or one of its own member types/
+    }
+
+    @Test // GROOVY-10125
+    void testTypeParamNoCycle() {
+        assertScript '''
+            class C<T, U extends T> {
+            }
+            new C<Number,Integer>()
+        '''
+    }
+
+    @Test
     void testInnerClassCycle1() {
         def err = shouldFail '''
             class C extends C.Inner {