You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/01/25 20:35:43 UTC

[groovy] branch master updated: GROOVY-9737: ClassNode#hasPossibleMethod must check super types

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c63a2a  GROOVY-9737: ClassNode#hasPossibleMethod must check super types
9c63a2a is described below

commit 9c63a2a6f336e932f0e988a517f4b8ff03e6bf93
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Jan 25 14:19:58 2021 -0600

    GROOVY-9737: ClassNode#hasPossibleMethod must check super types
---
 .../java/org/codehaus/groovy/ast/ClassNode.java    |  2 +-
 src/test/groovy/bugs/Groovy8964.groovy             | 53 ++++++++++++++++++----
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 49d2524..1fb076f 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -1268,7 +1268,7 @@ public class ClassNode extends AnnotatedNode {
         }
 
         for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
-            for (MethodNode mn : getDeclaredMethods(name)) {
+            for (MethodNode mn : cn.getDeclaredMethods(name)) {
                 if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
                     return true;
                 }
diff --git a/src/test/groovy/bugs/Groovy8964.groovy b/src/test/groovy/bugs/Groovy8964.groovy
index bdfa6f9..0a0e13a 100644
--- a/src/test/groovy/bugs/Groovy8964.groovy
+++ b/src/test/groovy/bugs/Groovy8964.groovy
@@ -27,23 +27,58 @@ final class Groovy8964 {
     @Test
     void testInstanceVarargMethodNotMaskedByStaticMethodWithSameNumberOfArgs() {
         assertScript '''
-            class Example {
-
-                def method(String... args) {
+            class C {
+                def m(String... args) {
                     'vararg'
                 }
-
-                static method(List<String> args, File workDirectory, Appendable out, Appendable err) {
+                static m(List<String> args, File workDirectory, Appendable out, Appendable err) {
                     'multi'
                 }
+                def test() {
+                    m('a', 'b', 'c', 'd')
+                }
+            }
+
+            assert new C().test() == 'vararg'
+        '''
+    }
+
+    @Test // GROOVY-9737
+    void testInstanceMethodNotMaskedByStaticMethodWithSameNumberOfArgs1() {
+        assertScript '''
+            abstract class A {
+                static void m(Integer i) {}
+                protected void m(String s) {}
+            }
 
-                def execute() {
-                    method("a", "b", "c", "d")
+            @groovy.transform.CompileStatic
+            class C extends A {
+                void test() {
+                    m('') // ClassCastException: class java.lang.Class cannot be cast to class A
                 }
             }
 
-            Example ex = new Example()
-            assert ex.execute() == 'vararg'
+            new C().test()
         '''
     }
+
+    @Test // GROOVY-9737
+    void testInstanceMethodNotMaskedByStaticMethodWithSameNumberOfArgs2() {
+        assertScript '''
+            import groovy.bugs.Groovy8964.A
+            @groovy.transform.CompileStatic
+            class C extends A {
+                void test() {
+                    m('') // VerifyError: Bad access to protected data in invokevirtual
+                }
+            }
+
+            new C().test()
+        '''
+    }
+
+    static abstract class A {
+        static void m(Integer i) {}
+        protected void m(String s) {}
+    }
 }