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 070063f  GROOVY-10339: STC: incorporate additional type witnesses for 
method call
070063f is described below

commit 070063f24df8936c1af8e168a14634219f548905
Author: Eric Milles <[email protected]>
AuthorDate: Tue Nov 2 17:07:26 2021 -0500

    GROOVY-10339: STC: incorporate additional type witnesses for method call
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java      |  5 ++++-
 src/test/groovy/transform/stc/GenericsSTCTest.groovy         | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 4ab4407..a2db17e 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5354,7 +5354,10 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                         Map<GenericsTypeName, GenericsType> connections = new 
HashMap<>();
                         extractGenericsConnections(connections, 
wrapTypeIfNecessary(argumentType), paramType);
                         connections.forEach((gtn, gt) -> 
resolvedPlaceholders.merge(gtn, gt, (gt1, gt2) -> {
-                            return gt2; // TODO
+                            // GROOVY-10339: incorporate additional witness
+                            ClassNode cn1 = makeClassSafe0(CLASS_Type, gt1);
+                            ClassNode cn2 = makeClassSafe0(CLASS_Type, gt2);
+                            return 
lowestUpperBound(cn1,cn2).getGenericsTypes()[0];
                         }));
                     }
                 }
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy 
b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 937c21c..925848a 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -550,6 +550,18 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10339
+    void testReturnTypeInferenceWithMethodGenerics21() {
+        shouldFailWithMessages '''
+            String foo() {
+            }
+            def <T> T bar(T x, T y) {
+            }
+            Integer i = bar(foo(), 1)
+        ''',
+        'Cannot assign value of type'
+    }
+
     void testDiamondInferrenceFromConstructor1() {
         assertScript '''
             class Foo<U> {

Reply via email to