Skip to content
Permalink
Browse files
GROOVY-7288: fix for @Delegate target that implements trait(s)
  • Loading branch information
eric-milles authored and paulk-asert committed Mar 20, 2022
1 parent 318eb4c commit c346617e929377842867809a866097e88e2a0a5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
@@ -38,7 +38,6 @@
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 void visit(final ASTNode[] nodes, final SourceUnit source) {
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) {
@@ -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 '''

0 comments on commit c346617

Please sign in to comment.