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  */
7 
8 class T8016177c {
9 
10     interface Function<X, Y> {
m(X x)11         Y m(X x);
12     }
13 
14     interface ExtFunction<X, Y> extends Function<X, Y> { }
15 
m1(Function<U, V> f)16     <U, V> U m1(Function<U, V> f) { return null; }
m1(ExtFunction<U, V> f)17     <U, V> U m1(ExtFunction<U, V> f) { return null; }
18 
m2(Function<Integer, Integer> f)19     void m2(Function<Integer, Integer> f) { }
m2(ExtFunction<Integer, Integer> f)20     void m2(ExtFunction<Integer, Integer> f) { }
21 
m3(Function<Integer, Integer> f)22     void m3(Function<Integer, Integer> f) { }
m3(ExtFunction<Object, Integer> f)23     void m3(ExtFunction<Object, Integer> f) { }
24 
g1(Object s)25     int g1(Object s) { return 1; }
26 
g2(Number s)27     int g2(Number s) { return 1; }
g2(Object s)28     int g2(Object s) { return 1; }
29 
test()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)
34 
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
38 
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
42 
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 }
48