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

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

commit 65236eb6029ac404456a467217203c7485ba3035
Author: Eric Milles <[email protected]>
AuthorDate: Sun Apr 13 09:45:38 2025 -0500

    GROOVY-11613: inner class of interface with default methods is static
---
 .../apache/groovy/parser/antlr4/AstBuilder.java    |  4 +-
 .../transform/trait/TraitASTTransformation.java    |  5 ++-
 src/test/groovy/bugs/Groovy11613.groovy            | 45 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java 
b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 3f8f362b32..f51ddc979d 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1263,7 +1263,9 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> {
                     outerClass
             );
         } else if (asBoolean(outerClass)) {
-            if (outerClass.isInterface()) modifiers |= Opcodes.ACC_STATIC;
+            if (outerClass.isInterface() || isTrue(outerClass, 
IS_INTERFACE_WITH_DEFAULT_METHODS)) { // GROOVY-11613
+                modifiers |= Opcodes.ACC_STATIC;
+            }
             classNode = new InnerClassNode(
                     outerClass,
                     outerClass.getName() + "$" + className,
diff --git 
a/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java 
b/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
index 033dfafd3c..ac06a928fb 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
@@ -171,8 +171,9 @@ public class TraitASTTransformation extends 
AbstractASTTransformation implements
                 ClassNode.EMPTY_ARRAY,
                 null
         );
-        helper.setStaticClass(true); // GROOVY-7242, GROOVY-7456, etc.
-        cNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE);
+        helper.setStaticClass(true); // GROOVY-7242, GROOVY-7456
+        cNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE
+                | (cNode.getOuterClass() != null ? ACC_STATIC : 0)); // 
GROOVY-11600, GROOVY-11613
 
         checkInnerClasses(cNode);
 
diff --git a/src/test/groovy/bugs/Groovy11613.groovy 
b/src/test/groovy/bugs/Groovy11613.groovy
new file mode 100644
index 0000000000..066cd348b7
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy11613.groovy
@@ -0,0 +1,45 @@
+/*
+ *  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 Groovy11613 {
+    @Test
+    void testInterfaceDefaultMethods() {
+        assertScript '''
+            interface Outer {
+                interface Inner extends Outer {
+                    default String foo() {
+                        'foo' + bar()
+                    }
+                }
+                default String bar() {
+                    'bar'
+                }
+            }
+
+            def object = new Outer.Inner() {}
+            def result = object.foo()
+            assert result == 'foobar'
+        '''
+    }
+}

Reply via email to