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 17:48:57 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10978: LUB of `Type` and `Type extends Bound>`
This is an automated email from the ASF dual-hosted git repository.
emilles 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 8fed3ff056 GROOVY-10978: LUB of `Type<T extends Bound>` and `Type<? extends Bound>`
8fed3ff056 is described below
commit 8fed3ff0562c333b570d808c4dcbade997ba7912
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 d0339c42df..dfa78e97d9 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 373bdd48d0..e0c927f8f1 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