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/17 23:02:15 UTC

[groovy] branch GROOVY-9524 created (now 45d0ee1)

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

emilles pushed a change to branch GROOVY-9524
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 45d0ee1  GROOVY-9524: enum const class extends enum class, so no this$0 for calls

This branch includes the following new commits:

     new 45d0ee1  GROOVY-9524: enum const class extends enum class, so no this$0 for calls

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[groovy] 01/01: GROOVY-9524: enum const class extends enum class, so no this$0 for calls

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 45d0ee12301f5fd92ee0837f2350d167ffc923ab
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 aff3014..6d0b8f4 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
@@ -246,7 +246,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'
+        '''
+    }
+}