Skip to content

Commit 691ee27

Browse files
committed
GROOVY-11241: add test case
1 parent bfa540e commit 691ee27

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

src/test/groovy/transform/stc/MethodReferenceTest.groovy

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,48 @@ final class MethodReferenceTest {
238238
'''
239239
}
240240

241+
@Test // class::instanceMethod -- GROOVY-11241
242+
void testFunctionCI9() {
243+
assertScript imports + '''
244+
@Grab('io.vavr:vavr:0.10.4')
245+
import io.vavr.control.*
246+
247+
Option<Integer> option() { Option.of(42) }
248+
249+
@CompileStatic
250+
Try<Integer> test() {
251+
Try.of{ option() }.<Integer>mapTry(Option::get)
252+
// ^^^^^^^^^
253+
}
254+
255+
assert test().get() == 42
256+
'''
257+
258+
def err = shouldFail imports + '''
259+
@Grab('io.vavr:vavr:0.10.4')
260+
import io.vavr.control.Try
261+
262+
class Option<X> {
263+
private final X x
264+
def X get() { x }
265+
static <Y> Option<Y> of(Y y) {
266+
new Option(x: y)
267+
}
268+
}
269+
270+
Option<Integer> option() { Option.of(666) }
271+
272+
@CompileStatic
273+
Try<Integer> test() {
274+
//Try.of { option() }.mapTry(Option::get)
275+
def try_of = Try.of { option() }
276+
def result = try_of.mapTry(Option::get)
277+
result
278+
}
279+
'''
280+
assert err =~ /Cannot (assign|return) io.vavr.control.Try <java.lang.Object> / // not <X> or <Option<Integer>>
281+
}
282+
241283
@Test // class::instanceMethod -- GROOVY-9974
242284
void testPredicateCI() {
243285
assertScript imports + '''

0 commit comments

Comments
 (0)