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 10:43:52 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 06e5fc035 -> f35bdac70


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/f35bdac7
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f35bdac7
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f35bdac7

Branch: refs/heads/master
Commit: f35bdac706f60b2af3ca937d749199d8a1b065a2
Parents: 06e5fc0
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:43:04 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/f35bdac7/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 fdbf350..1ca5429 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3593,7 +3593,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();
@@ -3602,7 +3602,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/f35bdac7/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