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 2023/03/17 16:44:19 UTC

[groovy] branch master updated: GROOVY-10978: LUB of `Type` and `Type`

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 b92cc2a895 GROOVY-10978: LUB of `Type<T extends Bound>` and `Type<? extends Bound>`
b92cc2a895 is described below

commit b92cc2a8957b33fc2ee4f5b9a8d8d302d22f9741
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Mar 17 11:44:03 2023 -0500

    GROOVY-10978: LUB of `Type<T extends Bound>` and `Type<? extends Bound>`
---
 .../groovy/ast/tools/WideningCategories.java       |  2 +-
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 56 ++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index 1bb248689e..d7ba138ff5 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -291,7 +291,7 @@ public class WideningCategories {
     }
 
     private static ClassNode upperBound(final GenericsType gt) {
-        if (gt.isWildcard()) {
+        if (gt.isPlaceholder() || gt.isWildcard()) {
             ClassNode[] ub = gt.getUpperBounds();
             if (ub != null) return ub[0];
         }
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index ea9b8215c4..acd936392b 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -376,6 +376,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10978
     void testReturnTypeInferenceWithMethodGenerics1x() {
         assertScript '''
             interface Handle {
@@ -402,6 +403,61 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
             def c = new HandleContainer(handle: h)
             test({k->c} as Input, {k->c} as State)
         '''
+
+        File parentDir = File.createTempDir()
+        config.with {
+            targetDirectory = File.createTempDir()
+            jointCompilationOptions = [memStub: true]
+        }
+        try {
+            def a = new File(parentDir, 'Handle.java')
+            a.write '''
+                interface Handle {
+                    int getCount();
+                }
+            '''
+            def b = new File(parentDir, 'HandleContainer.java')
+            b.write '''
+                class HandleContainer<H extends Handle> {
+                    H handle;
+                }
+            '''
+            def c = new File(parentDir, 'Input.java')
+            c.write '''
+                interface Input {
+                    HandleContainer<? extends Handle> getResult(Object key);
+                }
+            '''
+            def d = new File(parentDir, 'State.java')
+            d.write '''
+                interface State {
+                    <X extends Handle> HandleContainer<X> getResult(Object key);
+                }
+            '''
+            def e = new File(parentDir, 'Tester.groovy')
+            e.write '''
+                void test(Input input, State state) {
+                    def container = state.getResult('k') ?: input.getResult('k')
+                    Handle handle = container.handle
+                    Integer count = handle.count
+                    assert count == 1
+                }
+
+                Handle h = {->1}
+                def c = new HandleContainer(handle: h)
+                test({k->c} as Input, {k->c} as State)
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b, c, d, e)
+            cu.compile()
+
+            loader.loadClass('Tester').main()
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
     }
 
     // GROOVY-10067