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/11/01 00:10:48 UTC

[groovy] branch master updated: GROOVY-10315: STC: merge multiple witnesses for type parameter of method

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 8bc6523  GROOVY-10315: STC: merge multiple witnesses for type parameter of method
8bc6523 is described below

commit 8bc6523fe63a4aecc68639da3be2da3dbc4af57a
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Oct 31 19:10:39 2021 -0500

    GROOVY-10315: STC: merge multiple witnesses for type parameter of method
---
 .../transform/stc/StaticTypeCheckingSupport.java     | 12 +++++++++++-
 src/test/groovy/transform/stc/GenericsSTCTest.groovy | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

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 a7243a2..3c47f79 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -77,6 +77,7 @@ import static org.apache.groovy.ast.tools.ClassNodeUtils.samePackageName;
 import static org.apache.groovy.ast.tools.ExpressionUtils.isNullConstant;
 import static org.codehaus.groovy.ast.ClassHelper.BigInteger_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.Byte_TYPE;
+import static org.codehaus.groovy.ast.ClassHelper.CLASS_Type;
 import static org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.COLLECTION_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.Character_TYPE;
@@ -118,6 +119,7 @@ import static org.codehaus.groovy.ast.ClassHelper.make;
 import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching;
 import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.void_WRAPPER_TYPE;
+import static org.codehaus.groovy.ast.tools.GenericsUtils.makeClassSafe0;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isBigIntCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isFloatingCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
@@ -1587,7 +1589,15 @@ public abstract class StaticTypeCheckingSupport {
                 if (oldValue.isPlaceholder()) { // T=T or V, not T=String or ? ...
                     GenericsTypeName name = new GenericsTypeName(oldValue.getName());
                     GenericsType newValue = connections.get(name); // find "V" in T=V
-                    if (newValue == oldValue || name.getName().charAt(0) == '#') continue;
+                    if (newValue == oldValue) continue;
+                    if (newValue == null) { // GROOVY-10315
+                        newValue = connections.get(entry.getKey());
+                        if (newValue != null) {
+                            ClassNode o = makeClassSafe0(CLASS_Type, oldValue),
+                                      n = makeClassSafe0(CLASS_Type, newValue);
+                            newValue = lowestUpperBound(o,n).getGenericsTypes()[0];
+                        }
+                    }
                     if (newValue == null) {
                         entry.setValue(newValue = applyGenericsContext(connections, oldValue));
                         if (!checkForMorePlaceholders) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 47c4d64..2babe93 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1787,6 +1787,26 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10315
+    void testShouldUseMethodGenericType14() {
+        for (args in ['m2(), c.m()', 'c.m(), m2()']) {
+            assertScript """
+                class C<T> {
+                    def T m() {
+                    }
+                }
+                def <X> X m2() {
+                }
+                def <Y> void m3(Y y1, Y y2) {
+                }
+                def <Z> void test(C<Z> c) {
+                    m3($args)
+                }
+                test(new C<String>())
+            """
+        }
+    }
+
     // GROOVY-5516
     void testAddAllWithCollectionShouldBeAllowed() {
         assertScript '''import org.codehaus.groovy.transform.stc.ExtensionMethodNode