groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blackd...@apache.org
Subject groovy git commit: GROOVY-7927: use inferred type from closure to find connection to SAM return type
Date Sat, 03 Sep 2016 11:23:24 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 831550cc3 -> 776ea2cdf


GROOVY-7927: use inferred type from closure to find connection to SAM return type


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/776ea2cd
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/776ea2cd
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/776ea2cd

Branch: refs/heads/GROOVY_2_4_X
Commit: 776ea2cdfd2aa0ba1525354f62f1f49faa920ff4
Parents: 831550c
Author: Jochen Theodorou <blackdrag@gmx.org>
Authored: Sat Sep 3 12:43:04 2016 +0200
Committer: Jochen Theodorou <blackdrag@gmx.org>
Committed: Sat Sep 3 12:46:07 2016 +0200

----------------------------------------------------------------------
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java     | 4 ++--
 src/test/groovy/transform/stc/ClosuresSTCTest.groovy        | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/776ea2cd/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index a55f95f..5e5ebcc 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3572,7 +3572,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
         return null;
     }
 
-    private static ClassNode inferSAMTypeGenericsInAssignment(ClassNode samUsage, MethodNode
sam, ClassNode closureType, ClosureExpression closureExpression) {
+    private ClassNode inferSAMTypeGenericsInAssignment(ClassNode samUsage, MethodNode sam,
ClassNode closureType, ClosureExpression closureExpression) {
         // if the sam type or closure type do not provide generics information, 
         // we cannot infer anything, thus we simply return the provided samUsage
         GenericsType[] samGt = samUsage.getGenericsTypes();
@@ -3581,7 +3581,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
 
         // extract the generics from the return type
         Map<String,GenericsType> connections = new HashMap<String,GenericsType>();
-        extractGenericsConnections(connections,closureType,sam.getReturnType());
+        extractGenericsConnections(connections, getInferredReturnType(closureExpression),sam.getReturnType());
 
         // next we get the block parameter types and set the generics 
         // information just like before

http://git-wip-us.apache.org/repos/asf/groovy/blob/776ea2cd/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 1eaeca8..686336c 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -332,6 +332,15 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
             assert t.foo() == 2
         """
     }
+
+    // GROOVY-7927
+    void testSAMGenericsInAssignment() {
+        assertScript """
+            interface SAM<T,R> { R accept(T t); }
+            SAM<Integer,Integer> s = { Integer n -> -n }
+            assert s.accept(1) == -1
+        """
+    }
     
     void testSAMProperty() {
         assertScript """


Mime
View raw message