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/12/02 15:53:35 UTC

[groovy] branch master updated: GROOVY-8693: MOP method `super$1$name` not `super$2$name` for interfaces

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 6ccf8d7  GROOVY-8693: MOP method `super$1$name` not `super$2$name` for interfaces
6ccf8d7 is described below

commit 6ccf8d74afc81c70f75125f3ed347f7587d7c2e9
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Dec 2 09:40:05 2021 -0600

    GROOVY-8693: MOP method `super$1$name` not `super$2$name` for interfaces
    
      to match groovy.lang.MetaMethod#getMopName()
    
    org.codehaus.groovy.reflection.CachedClass#getSuperClassDistance() could
    have been bumped from 1 to 2 instead -- we just need both to be aligned.
---
 src/main/java/groovy/lang/MetaClassImpl.java                  |  2 +-
 src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index b16fe8c..6d986f0 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -530,7 +530,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
 
             private int mopArrayIndex(final MetaMethod method) {
                 if (method instanceof NewMetaMethod) return -1;
-                if (useThis ^ Modifier.isPrivate(method.getModifiers())) return -1;
+                if (useThis ^ method.isPrivate()) return -1;
 
                 String mopName = method.getMopName();
                 if (useThis) {
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java
index bfdd1e5..fa463ff 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java
@@ -144,10 +144,12 @@ public class MopWriter {
      * @return the mop method name
      */
     public static String getMopMethodName(final MethodNode method, final boolean useThis) {
-        ClassNode declaringNode = method.getDeclaringClass();
-        int distance = 0;
-        for (; declaringNode != null; declaringNode = declaringNode.getSuperClass()) {
-            distance += 1;
+        ClassNode declaringClass = method.getDeclaringClass();
+        int distance = 1;
+        if (!declaringClass.isInterface()) { // GROOVY-8693: fixed distance for interface methods
+            for (ClassNode sc = declaringClass.getSuperClass(); sc != null; sc = sc.getSuperClass()) {
+                distance += 1;
+            }
         }
         return (useThis ? "this" : "super") + "$" + distance + "$" + method.getName();
     }