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 2022/03/20 22:53:54 UTC

[groovy] branch GROOVY_4_0_X updated: GROOVY-7288: fix for `@Delegate` target that implements trait(s)

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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new c8921c6  GROOVY-7288: fix for `@Delegate` target that implements trait(s)
c8921c6 is described below

commit c8921c63a0535560a071ba904476e54ebd2e5e45
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Mar 18 10:38:01 2022 -0500

    GROOVY-7288: fix for `@Delegate` target that implements trait(s)
---
 .../groovy/transform/DelegateASTTransformation.java  |  3 +--
 .../traitx/TraitASTTransformationTest.groovy         | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/DelegateASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/DelegateASTTransformation.java
index e67a4e0..2c79b24 100644
--- a/src/main/java/org/codehaus/groovy/transform/DelegateASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/DelegateASTTransformation.java
@@ -38,7 +38,6 @@ import org.codehaus.groovy.ast.tools.BeanUtils;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 
-import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -199,7 +198,7 @@ public class DelegateASTTransformation extends AbstractASTTransformation {
             if (skipInterfaces) return;
 
             Set<ClassNode> addedInterfaces = getInterfacesAndSuperInterfaces(delegate.type);
-            addedInterfaces.removeIf(i -> !Modifier.isPublic(i.getModifiers()) || i.isSealed());
+            addedInterfaces.removeIf(i -> (i.getModifiers() & (ACC_PUBLIC | ACC_SYNTHETIC)) != ACC_PUBLIC || i.isSealed()); // GROOVY-7288 and JDK16+
             if (!addedInterfaces.isEmpty()) {
                 Set<ClassNode> ownerInterfaces = getInterfacesAndSuperInterfaces(delegate.owner);
                 for (ClassNode i : addedInterfaces) {
diff --git a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index b49bb91..09a2fb6 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -1773,6 +1773,26 @@ final class TraitASTTransformationTest {
         '''
     }
 
+    @Test // GROOVY-7288
+    void testClassWithTraitDelegate() {
+        assertScript '''
+            trait T {
+                final foo = 'bar'
+            }
+            class D implements T {
+                def m() {
+                    return 'baz'
+                }
+            }
+            class C { // The class must be declared abstract or the method 'java.lang.String T__foo$get()' must be implemented
+                private @Delegate D provider = new D()
+            }
+            def c = new C()
+            assert c.foo == 'bar'
+            assert c.m() == 'baz'
+        '''
+    }
+
     @Test // GROOVY-9739
     void testTraitExtendsTraitWithDelegate() {
         assertScript '''