groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Refine "GROOVY-7883 Static compiler prefers private constructor over public if private matches be(closes #705)"
Date Sat, 12 May 2018 07:06:22 GMT
Repository: groovy
Updated Branches:
  refs/heads/master b1d123277 -> 6560ce8e5


Refine "GROOVY-7883 Static compiler prefers private constructor over public if private matches
be(closes #705)"


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

Branch: refs/heads/master
Commit: 6560ce8e5541e4333a418d8dcf7f0f5ae92a71d0
Parents: b1d1232
Author: sunlan <sunlan@apache.org>
Authored: Sat May 12 15:06:11 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Sat May 12 15:06:11 2018 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          | 12 +++++-
 .../classgen/asm/sc/bugs/Groovy7883Bug.groovy   | 45 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6560ce8e/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
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 a4c93c5..a1a1c7e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4396,6 +4396,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
         boolean isEnclosingInnerClass = enclosingClassNode instanceof InnerClassNode;
         List<ClassNode> outerClasses = enclosingClassNode.getOuterClasses();
 
+        outer:
         for (MethodNode methodNode : methods) {
             if (methodNode instanceof ExtensionMethodNode) {
                 result.add(methodNode);
@@ -4407,8 +4408,15 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             if (isEnclosingInnerClass) {
                 for (ClassNode outerClass : outerClasses) {
                     if (outerClass.isDerivedFrom(declaringClass)) {
-                        result.add(methodNode);
-                        continue;
+                        if (outerClass.equals(declaringClass)) {
+                            result.add(methodNode);
+                            continue outer;
+                        } else {
+                            if (methodNode.isPublic() || methodNode.isProtected()) {
+                                result.add(methodNode);
+                                continue outer;
+                            }
+                        }
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6560ce8e/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7883Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7883Bug.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7883Bug.groovy
index 51a5b1b..a40fe4e 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7883Bug.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/Groovy7883Bug.groovy
@@ -127,4 +127,49 @@ class Groovy7883Bug extends GroovyTestCase {
         new B().m()
         '''
     }
+
+    void test7() {
+        assertScript '''
+        @groovy.transform.CompileStatic
+        class A {
+            protected void doIt(ArrayList al) { doIt2(al) }
+            private void doIt2(List list, String x = "abc") {}
+            public void doIt3() { }
+        }
+        
+        @groovy.transform.CompileStatic
+        class B extends A {
+            class C {
+                public void m() {
+                    doIt(new ArrayList());
+                    doIt3();
+                }
+            }
+            
+        }
+        
+        assert true
+        '''
+    }
+
+    void test8() {
+        def errMsg = shouldFail  '''
+        @groovy.transform.CompileStatic
+        class A {
+            protected void doIt(ArrayList al) { doIt2(al) }
+            private void doIt2(List list, String x = "abc") {}
+        }
+        
+        @groovy.transform.CompileStatic
+        class B extends A {
+            class C {
+                public void m() { doIt2(new ArrayList()) }
+            }
+            
+        }
+        
+        '''
+
+        assert errMsg.contains('[Static type checking] - Cannot find matching method B$C#doIt2(java.util.ArrayList)')
+    }
 }


Mime
View raw message