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/03/21 16:05:47 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9524: enum const class extends enum class, so no this$0 for calls

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

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


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 2eb3fec  GROOVY-9524: enum const class extends enum class, so no this$0 for calls
2eb3fec is described below

commit 2eb3fecf57124230a06570da32c9a87c6d9de4bb
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Mar 17 18:01:56 2021 -0500

    GROOVY-9524: enum const class extends enum class, so no this$0 for calls
---
 .../classgen/asm/sc/StaticInvocationWriter.java    |  3 +-
 src/test/groovy/bugs/Groovy9524.groovy             | 48 ++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index b9712a7..2a44af2 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -245,7 +245,8 @@ public class StaticInvocationWriter extends InvocationWriter {
             Expression fixedReceiver = receiver;
             if (implicitThis) {
                 if (!controller.isInGeneratedFunction()) {
-                    fixedReceiver = propX(classX(lookupClassNode), "this");
+                    if (!thisClass.isDerivedFrom(lookupClassNode))
+                        fixedReceiver = propX(classX(lookupClassNode), "this");
                 } else if (thisClass != null) {
                     ClassNode current = thisClass.getOuterClass();
                     fixedReceiver = varX("thisObject", current);
diff --git a/src/test/groovy/bugs/Groovy9524.groovy b/src/test/groovy/bugs/Groovy9524.groovy
new file mode 100644
index 0000000..e3dfa30
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9524.groovy
@@ -0,0 +1,48 @@
+/*
+ *  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
+
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy9524 {
+    @Test
+    void testEnumConstClassCallingPrivateMethod() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class W {
+                enum X {
+                    Y {
+                        def z() {
+                            truncate('foo', 2)
+                        }
+                    }
+
+                    abstract def z()
+
+                    private String truncate(String input, int maxLength) {
+                        input.substring(0, maxLength)
+                    }
+                }
+            }
+            assert W.X.Y.z() == 'fo'
+        '''
+    }
+}