You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/10/14 10:59:25 UTC

(groovy) branch master updated: GROOVY-12427: Joint compilation stub declares a precompiled trait's static methods "static abstract" on implementing classes

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

paulk-asert 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 237fdb54b3 GROOVY-12427: Joint compilation stub declares a precompiled trait's static methods "static abstract" on implementing classes
237fdb54b3 is described below

commit 237fdb54b39c4f9d27064aeca0870eadb0888da3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Oct 9 02:27:09 2026 +1000

    GROOVY-12427: Joint compilation stub declares a precompiled trait's static methods "static abstract" on implementing classes
---
 .../groovy/tools/javac/JavaStubGenerator.java      |  2 +-
 .../groovy/tools/stubgenerator/Groovy12427.groovy  | 56 ++++++++++++++++++++++
 .../tools/stubgenerator/Groovy12427Support.groovy  | 31 ++++++++++++
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index a5cddff8a8..e7d3f86c7f 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -863,7 +863,7 @@ public class JavaStubGenerator {
         if (!isInterfaceOrTrait(classNode)) {
             int modifiers = methodNode.getModifiers();
             if (classNode.isEnum()) modifiers &= ~Opcodes.ACC_ABSTRACT;
-            else if (isDefaultTraitImpl(methodNode)) modifiers ^= Opcodes.ACC_ABSTRACT;
+            else if (isDefaultTraitImpl(methodNode)) modifiers &= ~Opcodes.ACC_ABSTRACT; // GROOVY-12427: may be static
             if (methodNode.isSyntheticPublic() && hasPackageScopeXform(methodNode, PackageScopeTarget.METHODS)) modifiers &= ~Opcodes.ACC_PUBLIC;
 
             printModifiers(out, modifiers);
diff --git a/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427.groovy b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427.groovy
new file mode 100644
index 0000000000..ebe67bb700
--- /dev/null
+++ b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427.groovy
@@ -0,0 +1,56 @@
+/*
+ *  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 org.codehaus.groovy.tools.stubgenerator
+
+/**
+ * GROOVY-12427: the stub for a class implementing a precompiled trait must not
+ * declare the trait's static methods {@code static abstract}.
+ */
+final class Groovy12427 extends StringSourcesStubTestCase {
+
+    @Override
+    Map<String, String> provideSources() {
+        [
+            'Person.groovy': """
+                import ${this.class.name}Support
+
+                class Person implements ${this.class.simpleName}Support { }
+            """,
+            'UsesPerson.java': '''
+                public class UsesPerson {
+                    Person person = new Person();
+                    public String described = Person.describe();
+                    public String greeted = person.greet();
+                }
+            '''
+        ]
+    }
+
+    @Override
+    void verifyStubs() {
+        String stub = stubJavaSourceFor('Person')
+        assert !stub.contains('abstract')
+        assert stub =~ /public static\s+java\.lang\.String describe\(\)/
+        assert stub =~ /public\s+java\.lang\.String greet\(\)/
+
+        def usesPerson = loader.loadClass('UsesPerson').getDeclaredConstructor().newInstance()
+        assert usesPerson.described == 'named'
+        assert usesPerson.greeted == 'hi'
+    }
+}
diff --git a/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427Support.groovy b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427Support.groovy
new file mode 100644
index 0000000000..35989adb36
--- /dev/null
+++ b/src/test/groovy/org/codehaus/groovy/tools/stubgenerator/Groovy12427Support.groovy
@@ -0,0 +1,31 @@
+/*
+ *  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 org.codehaus.groovy.tools.stubgenerator
+
+import groovy.transform.Virtual
+
+/**
+ * Precompiled trait for {@link Groovy12427}: compiled with the test sources,
+ * so it is seen as a decompiled class node during the joint compilation.
+ */
+trait Groovy12427Support {
+    static String describe() { 'named' }
+    @Virtual static String kind() { 'virtual' }
+    String greet() { 'hi' }
+}