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 2022/01/31 18:00:23 UTC
[groovy] 04/05: 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_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b16f6cd19987ba300247421dac0605c6f429696c
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
Conflicts:
src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
---
.../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 b385ee4..93940a9 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
@@ -243,7 +243,8 @@ public class StaticInvocationWriter extends InvocationWriter {
Expression fixedReceiver = receiver;
if (implicitThis) {
if (!controller.isInClosure()) {
- fixedReceiver = new PropertyExpression(new ClassExpression(lookupClassNode), "this");
+ if (!thisClass.isDerivedFrom(lookupClassNode))
+ fixedReceiver = new PropertyExpression(new ClassExpression(lookupClassNode), "this");
} else if (thisClass != null) {
ClassNode current = thisClass.getOuterClass();
fixedReceiver = new VariableExpression("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'
+ '''
+ }
+}