Tue, 10 Sep 2013 13:47:51 +0200
8005222: Fixed bugs should have tests with bugid in @bug tag
Reviewed-by: jfranck, jjg
Contributed-by: Andreas Lundblad <andreas.lundblad@oracle.com>
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * @test /nodynamiccopyright/ |
aoqi@0 | 3 | * @bug 8016081 8016178 |
aoqi@0 | 4 | * @summary structural most specific and stuckness |
aoqi@0 | 5 | * @compile/fail/ref=T8016177c.out -XDrawDiagnostics T8016177c.java |
aoqi@0 | 6 | */ |
aoqi@0 | 7 | |
aoqi@0 | 8 | class T8016177c { |
aoqi@0 | 9 | |
aoqi@0 | 10 | interface Function<X, Y> { |
aoqi@0 | 11 | Y m(X x); |
aoqi@0 | 12 | } |
aoqi@0 | 13 | |
aoqi@0 | 14 | interface ExtFunction<X, Y> extends Function<X, Y> { } |
aoqi@0 | 15 | |
aoqi@0 | 16 | <U, V> U m1(Function<U, V> f) { return null; } |
aoqi@0 | 17 | <U, V> U m1(ExtFunction<U, V> f) { return null; } |
aoqi@0 | 18 | |
aoqi@0 | 19 | void m2(Function<Integer, Integer> f) { } |
aoqi@0 | 20 | void m2(ExtFunction<Integer, Integer> f) { } |
aoqi@0 | 21 | |
aoqi@0 | 22 | void m3(Function<Integer, Integer> f) { } |
aoqi@0 | 23 | void m3(ExtFunction<Object, Integer> f) { } |
aoqi@0 | 24 | |
aoqi@0 | 25 | int g1(Object s) { return 1; } |
aoqi@0 | 26 | |
aoqi@0 | 27 | int g2(Number s) { return 1; } |
aoqi@0 | 28 | int g2(Object s) { return 1; } |
aoqi@0 | 29 | |
aoqi@0 | 30 | void test() { |
aoqi@0 | 31 | m1((Integer x)->x); //ok - explicit lambda - subtyping picks most specific |
aoqi@0 | 32 | m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific |
aoqi@0 | 33 | m3((Integer x)->x); //ok - explicit lambda (only one applicable) |
aoqi@0 | 34 | |
aoqi@0 | 35 | m1(x->1); //ok - stuck lambda but nominal most specific wins |
aoqi@0 | 36 | m2(x->1); //ok - stuck lambda but nominal most specific wins |
aoqi@0 | 37 | m3(x->1); //ambiguous - implicit lambda & different params |
aoqi@0 | 38 | |
aoqi@0 | 39 | m1(this::g1); //ok - unambiguous ref - subtyping picks most specific |
aoqi@0 | 40 | m2(this::g1); //ok - unambiguous ref - subtyping picks most specific |
aoqi@0 | 41 | m3(this::g1); //ambiguous - both applicable, neither most specific |
aoqi@0 | 42 | |
aoqi@0 | 43 | m1(this::g2); //ok - stuck mref but nominal most specific wins |
aoqi@0 | 44 | m2(this::g2); //ok - stuck mref but nominal most specific wins |
aoqi@0 | 45 | m3(this::g2); //ambiguous - different params |
aoqi@0 | 46 | } |
aoqi@0 | 47 | } |