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 2022/09/09 20:10:05 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-10756: STC: retain bounds within super class generics

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

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


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 4ac269c730 GROOVY-10756: STC: retain bounds within super class generics
4ac269c730 is described below

commit 4ac269c730b9a783de52fa90b1d31321f27148db
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Sep 9 14:27:15 2022 -0500

    GROOVY-10756: STC: retain bounds within super class generics
---
 .../groovy/transform/stc/StaticTypeCheckingSupport.java     | 13 ++++++-------
 .../transform/stc/ClosureParamTypeInferenceSTCTest.groovy   | 12 ++++++++++++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 41e95f748a..26a59aa92b 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1796,19 +1796,18 @@ public abstract class StaticTypeCheckingSupport {
         } else if (type.equals(target) || !implementsInterfaceOrIsSubclassOf(type, target)) {
             extractGenericsConnections(connections, type.getGenericsTypes(), target.getGenericsTypes());
 
-        } else {
-            // find matching super class or interface
+        } else { // find matching super class or interface
             ClassNode superClass = GenericsUtils.getSuperClass(type, target);
             if (superClass != null) {
                 if (GenericsUtils.hasUnresolvedGenerics(superClass)) {
-                    Map<String, ClassNode> spec = GenericsUtils.createGenericsSpec(type);
-                    if (!spec.isEmpty()) {
-                        superClass = GenericsUtils.correctToGenericsSpecRecurse(spec, superClass);
-                    }
+                    // propagate type arguments to the super class or interface
+                    Map<GenericsTypeName, GenericsType> spec = new HashMap<>();
+                    extractGenericsConnections(spec, type.getGenericsTypes(),
+                                    type.redirect().getGenericsTypes());
+                    superClass = applyGenericsContext(spec, superClass);
                 }
                 extractGenericsConnections(connections, superClass, target);
             } else {
-                // if we reach here, we have an unhandled case
                 throw new GroovyBugError("The type " + type + " seems not to normally extend " + target + ". Sorry, I cannot handle this.");
             }
         }
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index fa7e98430c..619c3c2232 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -1460,4 +1460,16 @@ class ClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
             }
         '''
     }
+
+    static class Java10756 {
+        static <T extends File> Collection<T> getFiles() {
+        }
+    }
+
+    void testGroovy10756() {
+        assertScript """import ${Java10756.name.replace('$','.')}
+            Java10756.files?.collect { it.name }
+            //                         ^^ File
+        """
+    }
 }