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/03/18 15:47:47 UTC

[groovy] branch GROOVY-7288 created (now f27ad11)

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

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


      at f27ad11  GROOVY-7288: fix for `@Delegate` target that implements trait(s)

This branch includes the following new commits:

     new f27ad11  GROOVY-7288: fix for `@Delegate` target that implements trait(s)

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-7288: fix for `@Delegate` target that implements trait(s)

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

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

commit f27ad11fb5673233208a64bc3abc9e27e1ec0df1
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 ca9289e..621d43c 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 '''