Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 7a685f4e9 -> 5cee00956


GROOVY-8445: Static analysis does not work properly when coercing Closure to 
FunctionInterface


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 5cee00956bc85cd034afbdde8773abb991264c33
Parents: 7a685f4
Author: sunlan <sun...@apache.org>
Authored: Fri Feb 2 18:03:03 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Fri Feb 2 18:03:03 2018 +0800

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ClassHelper.java           | 9 ++++++++-
 src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java   | 7 +++++++
 .../groovy/transform/stc/StaticTypeCheckingSupport.java     | 8 ++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/5cee0095/src/main/org/codehaus/groovy/ast/ClassHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassHelper.java 
b/src/main/org/codehaus/groovy/ast/ClassHelper.java
index 60eaa47..98a1ba2 100644
--- a/src/main/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/org/codehaus/groovy/ast/ClassHelper.java
@@ -399,7 +399,14 @@ public class ClassHelper {
     public static MethodNode findSAM(ClassNode type) {
         if (!Modifier.isAbstract(type.getModifiers())) return null;
         if (type.isInterface()) {
-            List<MethodNode> methods = type.getMethods();
+            List<MethodNode> methods;
+            if (type.isInterface()) {
+                // e.g. BinaryOperator extends BiFunction, BinaryOperator 
contains no abstract method, but it is really a SAM
+                methods = type.redirect().getAllDeclaredMethods();
+            } else {
+                methods = type.getMethods();
+            }
+
             MethodNode found = null;
             for (MethodNode mi : methods) {
                 // ignore methods, that are not abstract and from Object

http://git-wip-us.apache.org/repos/asf/groovy/blob/5cee0095/src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java 
b/src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 366366c..41fab29 100644
--- a/src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -444,6 +444,13 @@ public class GenericsUtils {
             // have first to find matching super class or interface
             Map <String,ClassNode> genSpec = createGenericsSpec(type);
             ClassNode superClass = ClassHelper.getNextSuperClass(type,target);
+
+            if (superClass == null) {
+                if (ClassHelper.isPrimitiveType(type)) {
+                    superClass = 
ClassHelper.getNextSuperClass(ClassHelper.getWrapper(type), target);
+                }
+            }
+
             if (superClass!=null){
                 ClassNode corrected = 
GenericsUtils.correctToGenericsSpecRecurse(genSpec, superClass);
                 extractSuperClassGenerics(corrected, target, spec);

http://git-wip-us.apache.org/repos/asf/groovy/blob/5cee0095/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java 
b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 1a2f11e..b23cf2b 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.transform.stc;
 
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.MethodNode;
@@ -1757,6 +1758,13 @@ public abstract class StaticTypeCheckingSupport {
             // have first to find matching super class or interface
             Map <String,ClassNode> genSpec = 
GenericsUtils.createGenericsSpec(type);
             ClassNode superClass = getNextSuperClass(type,target);
+
+            if (superClass == null) {
+                if (ClassHelper.isPrimitiveType(type)) {
+                    superClass = 
ClassHelper.getNextSuperClass(ClassHelper.getWrapper(type), target);
+                }
+            }
+
             if (superClass!=null){
                 ClassNode corrected;
                 if (missesGenericsTypes(type)) {

Reply via email to