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 2020/09/25 22:16:33 UTC
[groovy] branch master updated: GROOVY-9555: add test case
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 aefc40b GROOVY-9555: add test case
aefc40b is described below
commit aefc40b0dac30c2630d342925a84db462fa2726a
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Sep 25 17:16:21 2020 -0500
GROOVY-9555: add test case
---
.../groovy/transform/stc/GenericsSTCTest.groovy | 65 ++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 6ddc989..a22e6ac 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -19,6 +19,7 @@
package groovy.transform.stc
import groovy.test.NotYetImplemented
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
/**
* Unit tests for static type checking : generics.
@@ -240,6 +241,70 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
''', 'Number'
}
+ // GROOVY-9555
+ void testAssignmentShouldWorkForProperUpperBound() {
+ assertScript '''
+ interface I<T> {
+ }
+ class C implements I<Object> {
+ }
+ interface Factory {
+ def <T extends I> T getInstance(Class<T> clazz)
+ }
+
+ void test(Factory f) {
+ C c = f.getInstance(C)
+ assert c instanceof C
+ assert c instanceof I
+ }
+ test { Class clazz -> clazz.newInstance() }
+ '''
+
+ config.with {
+ targetDirectory = File.createTempDir()
+ jointCompilationOptions = [stubDir: File.createTempDir()]
+ }
+ File parentDir = File.createTempDir()
+ try {
+ def a = new File(parentDir, 'Face.java')
+ a.write '''
+ public interface Face<T> {
+ }
+ '''
+ def b = new File(parentDir, 'Impl.java')
+ b.write '''
+ public class Impl implements Face<Object> {
+ }
+ '''
+ def c = new File(parentDir, 'Supplier.java')
+ c.write '''
+ public interface Supplier {
+ public <T extends Face> T getInstance(Class<T> clazz);
+ }
+ '''
+ def d = new File(parentDir, 'Tester.groovy')
+ d.write '''
+ void test(Supplier s) {
+ def x = s.getInstance(Impl)
+ assert x instanceof Impl
+ assert x instanceof Face
+ }
+ test { Class clazz -> clazz.newInstance() }
+ '''
+
+ def loader = new GroovyClassLoader(this.class.classLoader)
+ def cu = new JavaAwareCompilationUnit(config, loader)
+ cu.addSources(a, b, c, d)
+ cu.compile()
+
+ loader.loadClass('Tester').main()
+ } finally {
+ parentDir.deleteDir()
+ config.targetDirectory.deleteDir()
+ config.jointCompilationOptions.stubDir.deleteDir()
+ }
+ }
+
void testGroovy5154() {
assertScript '''
class Foo {