Skip to content
Permalink
Browse files
add test case
  • Loading branch information
eric-milles committed Apr 6, 2022
1 parent 0a9da2a commit 17f1055282256a0d0caca101d303f4b9b345c352
Showing 1 changed file with 34 additions and 6 deletions.
@@ -342,16 +342,16 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
// GROOVY-10051
void testReturnTypeInferenceWithMethodGenerics10() {
assertScript '''
abstract class State<H extends Handle> {
// Why not return HandleContainer<H>? I can't really say.
def <T extends Handle> HandleContainer<T> getHandleContainer(key) {
}
interface Handle {
Result getResult()
}
class HandleContainer<H extends Handle> {
H handle
}
interface Handle {
Result getResult()
abstract class State<H extends Handle> {
// Why not return HandleContainer<H>? I can't really say.
def <T extends Handle> HandleContainer<T> getHandleContainer(key) {
}
}
class Result {
int itemCount
@@ -376,6 +376,34 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}

void testReturnTypeInferenceWithMethodGenerics1x() {
assertScript '''
interface Handle {
int getCount()
}
class HandleContainer<H extends Handle> {
H handle
}
interface Input {
HandleContainer<? extends Handle> getResult(key)
}
interface State {
def <X extends Handle> HandleContainer<X> getResult(key)
}
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)
'''
}

// GROOVY-10067
void testReturnTypeInferenceWithMethodGenerics11() {
assertScript '''

0 comments on commit 17f1055

Please sign in to comment.