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

emilles 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 6a3d9424a4 GROOVY-8299, GROOVY-11549: add covariant methods to native 
interfaces
6a3d9424a4 is described below

commit 6a3d9424a479c3d684dc2d70f83162d3d88a3cf0
Author: Eric Milles <[email protected]>
AuthorDate: Sun Feb 16 12:11:54 2025 -0600

    GROOVY-8299, GROOVY-11549: add covariant methods to native interfaces
---
 .../org/codehaus/groovy/classgen/Verifier.java     |  4 +-
 src/test/gls/invocation/CovariantReturnTest.groovy | 20 +++++-
 .../transform/AutoImplementTransformTest.groovy    | 76 +++++++---------------
 3 files changed, 43 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java 
b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index 1f766ce371..195ac34d77 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -247,8 +247,8 @@ public class Verifier implements GroovyClassVisitor, 
Opcodes {
                 node.setNodeMetaData(ClassNodeSkip.class, Boolean.TRUE);
             }
             if (node.isInterface()) {
-                // GROOVY-11273
-                checkFinalVariables(node);
+                addCovariantMethods(node); // GROOVY-8299
+                checkFinalVariables(node); // GROOVY-11273
             }
             return;
         }
diff --git a/src/test/gls/invocation/CovariantReturnTest.groovy 
b/src/test/gls/invocation/CovariantReturnTest.groovy
index cdff82ea6e..98510ce6f7 100644
--- a/src/test/gls/invocation/CovariantReturnTest.groovy
+++ b/src/test/gls/invocation/CovariantReturnTest.groovy
@@ -195,7 +195,7 @@ final class CovariantReturnTest {
     }
 
     @Test
-    void testCovariantReturnFromGenericsInterface() {
+    void testDeclaredMethodCovariantReturnForParameterizedType() {
         assertScript '''
             class Task implements java.util.concurrent.Callable<List> {
                 List call() throws Exception {
@@ -207,6 +207,24 @@ final class CovariantReturnTest {
         '''
     }
 
+    // GROOVY-11549
+    @Test
+    void testDefaultMethodCovariantReturnForParameterizedType() {
+        assertScript '''
+            interface A<T> {
+                T m()
+            }
+            interface B extends A<String> {
+                @Override
+                default String m() {
+                    return 'B'
+                }
+            }
+
+            assert 2 == B.declaredMethods.count { it.name == 'm' }
+        '''
+    }
+
     // GROOVY-7849
     @Test
     void testCovariantArrayReturnType1() {
diff --git 
a/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy 
b/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
index a9821fb1ab..6f1a1fe43d 100644
--- a/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/AutoImplementTransformTest.groovy
@@ -223,83 +223,51 @@ final class AutoImplementTransformTest {
     @Test
     void testCovariantReturnTypes() {
         assertScript shell, '''
-            interface Super { List findAll() }
-            interface Sub extends Super { Iterable findAll() }
+            interface A { Iterable findAll() }
+            interface B extends A { List findAll() }
 
             @AutoImplement
-            class ThisClassFails implements Sub{}
+            class C implements B { }
 
-            assert !(new ThisClassFails().findAll())
+            assert !(new C().findAll())
         '''
 
-        assertScript shell, '''
-            interface Super { ArrayList findAll() }
-            interface Sub extends Super { Iterable findAll() }
-
-            @AutoImplement
-            class ThisClassFails implements Sub{}
-
-            assert !(new ThisClassFails().findAll())
-        '''
-
-        assertScript shell, '''
-            interface Super { Iterable findAll() }
-            interface Sub extends Super { List findAll() }
-
-            @AutoImplement
-            class ThisClassFails implements Sub{}
-
-            assert !(new ThisClassFails().findAll())
-        '''
-
-        assertScript shell, '''
-            interface Super { Iterable findAll() }
-            interface Sub extends Super { ArrayList findAll() }
+        def err = shouldFail shell, '''
+            interface A { List findAll() }
+            interface B extends A { Iterable findAll() }
 
             @AutoImplement
-            class ThisClassFails implements Sub{}
-
-            assert !(new ThisClassFails().findAll())
+            class C implements B { }
         '''
+        assert err =~ /The return type of java.lang.Iterable findAll\(\) in B 
is incompatible with java.util.List in A/
 
         assertScript shell, '''
-            interface Super { AbstractList findAll() }
-            interface Sub extends Super { List findAll() }
+            interface A { Iterable findAll() }
+            interface B extends A { ArrayList findAll() }
 
             @AutoImplement
-            class ThisClassFails implements Sub{}
+            class C implements B { }
 
-            assert !(new ThisClassFails().findAll())
+            assert !(new C().findAll())
         '''
 
-        assertScript shell, '''
-            interface Super { List findAll() }
-            interface Sub extends Super { AbstractList findAll() }
+        err = shouldFail shell, '''
+            interface A { ArrayList findAll() }
+            interface B extends A { Iterable findAll() }
 
             @AutoImplement
-            class ThisClassFails implements Sub{}
-
-            assert !(new ThisClassFails().findAll())
-        '''
-
-        assertScript shell, '''
-            interface Super { AbstractList findAll() }
-            interface Sub extends Super { ArrayList findAll() }
-
-            @AutoImplement
-            class ThisClassFails implements Sub{}
-
-            assert !(new ThisClassFails().findAll())
+            class C implements B { }
         '''
+        assert err =~ /The return type of java.lang.Iterable findAll\(\) in B 
is incompatible with java.util.ArrayList in A/
 
         assertScript shell, '''
-            interface Super { ArrayList findAll() }
-            interface Sub extends Super { AbstractList findAll() }
+            interface A { AbstractList findAll() }
+            interface B extends A { ArrayList findAll() }
 
             @AutoImplement
-            class ThisClassFails implements Sub{}
+            class C implements B { }
 
-            assert !(new ThisClassFails().findAll())
+            assert !(new C().findAll())
         '''
     }
 

Reply via email to