You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/05/11 19:32:12 UTC

groovy git commit: Revert "GROOVY-7883: Static compiler prefers private constructor over public if private matches better"

Repository: groovy
Updated Branches:
  refs/heads/master 3a0696ee3 -> affc8b9b8


Revert "GROOVY-7883: Static compiler prefers private constructor over public if private matches better"


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

Branch: refs/heads/master
Commit: affc8b9b82d0a0cbfcd364d2caf5baaf79d47f38
Parents: 3a0696e
Author: danielsun1106 <re...@hotmail.com>
Authored: Sat May 12 03:31:25 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sat May 12 03:31:47 2018 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          |  19 ---
 src/test/groovy/bugs/Groovy7883Bug.groovy       | 130 -------------------
 2 files changed, 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/affc8b9b/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 85daa8c..a6067c2 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4357,7 +4357,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
         // lookup in DGM methods too
         findDGMMethodsByNameAndArguments(getTransformLoader(), receiver, name, args, methods);
-        methods = filterMethodsByVisibility(methods);
         List<MethodNode> chosen = chooseBestMethod(receiver, methods, args);
         if (!chosen.isEmpty()) return chosen;
 
@@ -4384,24 +4383,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         return EMPTY_METHODNODE_LIST;
     }
 
-    private List<MethodNode> filterMethodsByVisibility(List<MethodNode> methods) {
-        List<MethodNode> result = new LinkedList<>();
-
-        ClassNode enclosingClassNode = typeCheckingContext.getEnclosingClassNode();
-        for (MethodNode methodNode : methods) {
-            if (methodNode.isPrivate() && !enclosingClassNode.equals(methodNode.getDeclaringClass())) {
-                continue;
-            }
-            if (methodNode.isProtected() && !enclosingClassNode.isDerivedFrom(methodNode.getDeclaringClass())) {
-                continue;
-            }
-
-            result.add(methodNode);
-        }
-
-        return result;
-    }
-
     /**
      * Given a method name and a prefix, returns the name of the property that should be looked up,
      * following the java beans rules. For example, "getName" would return "name", while

http://git-wip-us.apache.org/repos/asf/groovy/blob/affc8b9b/src/test/groovy/bugs/Groovy7883Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7883Bug.groovy b/src/test/groovy/bugs/Groovy7883Bug.groovy
deleted file mode 100644
index c164118..0000000
--- a/src/test/groovy/bugs/Groovy7883Bug.groovy
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package groovy.bugs
-
-class Groovy7883Bug extends GroovyTestCase {
-    void testGroovy7883() {
-        assertScript '''
-        @groovy.transform.CompileStatic
-        void doIt() {
-            throw new AssertionError("abc")
-        }
-        
-        try {
-            doIt()
-            assert false: "should never reach here"
-        } catch (AssertionError e) {
-            assert 'abc' == e.message
-        }
-        '''
-    }
-
-    void test2() {
-        def errMsg = shouldFail '''
-        @groovy.transform.CompileStatic
-        class A {
-            private void doIt() {}
-        }
-        
-        @groovy.transform.CompileStatic
-        class B {
-            public void m() { new A().doIt() }
-        }
-        
-        new B().m()
-        '''
-
-        assert errMsg.contains('[Static type checking] - Cannot find matching method A#doIt()')
-    }
-
-    void test3() {
-        def errMsg = shouldFail '''
-        @groovy.transform.CompileStatic
-        class A {
-            protected void doIt() {}
-        }
-        
-        @groovy.transform.CompileStatic
-        class B {
-            public void m() { new A().doIt() }
-        }
-        
-        new B().m()
-        '''
-
-        assert errMsg.contains('[Static type checking] - Cannot find matching method A#doIt()')
-    }
-
-    void test4() {
-        def errMsg = shouldFail '''
-        @groovy.transform.CompileStatic
-        class A {
-            private void doIt() {}
-        }
-        
-        @groovy.transform.CompileStatic
-        class B extends A {
-            public void m() { doIt() }
-        }
-        
-        new B().m()
-        '''
-
-        assert errMsg.contains('[Static type checking] - Cannot find matching method B#doIt()')
-    }
-
-    /**
-     * ensure the filtering logic does not break any code
-     */
-    void test5() {
-        assertScript '''
-        @groovy.transform.CompileStatic
-        class A {
-            protected void doIt() { doIt2() }
-            private void doIt2() {}
-            public void doIt3() { doIt() }
-        }
-        
-        @groovy.transform.CompileStatic
-        class B extends A {
-            public void m() { doIt() }
-        }
-        
-        new B().m()
-        new B().doIt3()
-        '''
-    }
-
-    void test6() {
-        assertScript '''
-        @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 {
-            public void m() { doIt(new ArrayList()) }
-        }
-        
-        new B().m()
-        '''
-    }
-}