Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 96748cca8 -> c6f1a8151


GROOVY-8439: @CompileStatic cannot compile generic class's static method

(cherry picked from commit 7b73c6a)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: c6f1a815133ceef9234fa2da5ccf51b4d5f82367
Parents: 96748cc
Author: danielsun1106 <realblue...@hotmail.com>
Authored: Sat Mar 10 22:41:11 2018 +0800
Committer: danielsun1106 <realblue...@hotmail.com>
Committed: Sat Mar 10 22:41:11 2018 +0800

----------------------------------------------------------------------
 .../transform/stc/StaticTypeCheckingSupport.java      | 14 ++++++++++----
 .../transform/stc/StaticTypeCheckingVisitor.java      |  2 ++
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c6f1a815/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 0e08127..734e618 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -2010,10 +2010,16 @@ public abstract class StaticTypeCheckingSupport {
     }
 
     static Map<String, GenericsType> 
extractGenericsParameterMapOfThis(MethodNode mn) {
-        if (mn==null) return null;
-        Map<String, GenericsType> map = 
getGenericsParameterMapOfThis(mn.getDeclaringClass());
-        map = mergeGenerics(map, mn.getGenericsTypes());
-        return map;
+        if (mn == null) return null;
+
+        Map<String, GenericsType> map;
+        if (mn.isStatic()) {
+            map = new HashMap<>();
+        } else {
+            map = getGenericsParameterMapOfThis(mn.getDeclaringClass());
+        }
+
+        return mergeGenerics(map, mn.getGenericsTypes());
     }
 
     private static Map<String, GenericsType> mergeGenerics(Map<String, 
GenericsType> current, GenericsType[] newGenerics) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/c6f1a815/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 93ea99c..dbc5dc6 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2709,6 +2709,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                             }
                     }
                     boolean lastArg = i == length - 1;
+
                     if (lastArg && inferredType.isArray()) {
                         if 
(inferredType.getComponentType().equals(originType)) {
                             inferredType = originType;
@@ -2716,6 +2717,7 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                     } else if 
(!typeCheckMethodArgumentWithGenerics(originType, inferredType, lastArg)) {
                         addError("Expected parameter of type "+ 
inferredType.toString(false)+" but got "+originType.toString(false), 
closureParam.getType());
                     }
+
                     
typeCheckingContext.controlStructureVariables.put(closureParam, inferredType);
                 }
             }

Reply via email to