Mon, 02 Sep 2013 22:38:36 +0100
8016177: structural most specific and stuckness
Reviewed-by: jjg, vromero
Contributed-by: maurizio.cimadamore@oracle.com
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8016081 8016178
4 * @summary structural most specific and stuckness
5 * @compile/fail/ref=T8016177c.out -XDrawDiagnostics T8016177c.java
6 */
8 class T8016177c {
10 interface Function<X, Y> {
11 Y m(X x);
12 }
14 interface ExtFunction<X, Y> extends Function<X, Y> { }
16 <U, V> U m1(Function<U, V> f) { return null; }
17 <U, V> U m1(ExtFunction<U, V> f) { return null; }
19 void m2(Function<Integer, Integer> f) { }
20 void m2(ExtFunction<Integer, Integer> f) { }
22 void m3(Function<Integer, Integer> f) { }
23 void m3(ExtFunction<Object, Integer> f) { }
25 int g1(Object s) { return 1; }
27 int g2(Number s) { return 1; }
28 int g2(Object s) { return 1; }
30 void test() {
31 m1((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
32 m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
33 m3((Integer x)->x); //ok - explicit lambda (only one applicable)
35 m1(x->1); //ok - stuck lambda but nominal most specific wins
36 m2(x->1); //ok - stuck lambda but nominal most specific wins
37 m3(x->1); //ambiguous - implicit lambda & different params
39 m1(this::g1); //ok - unambiguous ref - subtyping picks most specific
40 m2(this::g1); //ok - unambiguous ref - subtyping picks most specific
41 m3(this::g1); //ambiguous - both applicable, neither most specific
43 m1(this::g2); //ok - stuck mref but nominal most specific wins
44 m2(this::g2); //ok - stuck mref but nominal most specific wins
45 m3(this::g2); //ambiguous - different params
46 }
47 }