test/tools/javac/lambda/8016177/T8016177c.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/8016177/T8016177c.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,47 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8016081 8016178
     1.7 + * @summary structural most specific and stuckness
     1.8 + * @compile/fail/ref=T8016177c.out -XDrawDiagnostics T8016177c.java
     1.9 + */
    1.10 +
    1.11 +class T8016177c {
    1.12 +
    1.13 +    interface Function<X, Y> {
    1.14 +        Y m(X x);
    1.15 +    }
    1.16 +
    1.17 +    interface ExtFunction<X, Y> extends Function<X, Y> { }
    1.18 +
    1.19 +    <U, V> U m1(Function<U, V> f) { return null; }
    1.20 +    <U, V> U m1(ExtFunction<U, V> f) { return null; }
    1.21 +
    1.22 +    void m2(Function<Integer, Integer> f) { }
    1.23 +    void m2(ExtFunction<Integer, Integer> f) { }
    1.24 +
    1.25 +    void m3(Function<Integer, Integer> f) { }
    1.26 +    void m3(ExtFunction<Object, Integer> f) { }
    1.27 +
    1.28 +    int g1(Object s) { return 1; }
    1.29 +
    1.30 +    int g2(Number s) { return 1; }
    1.31 +    int g2(Object s) { return 1; }
    1.32 +
    1.33 +    void test() {
    1.34 +        m1((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
    1.35 +        m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
    1.36 +        m3((Integer x)->x); //ok - explicit lambda (only one applicable)
    1.37 +
    1.38 +        m1(x->1); //ok - stuck lambda but nominal most specific wins
    1.39 +        m2(x->1); //ok - stuck lambda but nominal most specific wins
    1.40 +        m3(x->1); //ambiguous - implicit lambda & different params
    1.41 +
    1.42 +        m1(this::g1); //ok - unambiguous ref - subtyping picks most specific
    1.43 +        m2(this::g1); //ok - unambiguous ref - subtyping picks most specific
    1.44 +        m3(this::g1); //ambiguous - both applicable, neither most specific
    1.45 +
    1.46 +        m1(this::g2); //ok - stuck mref but nominal most specific wins
    1.47 +        m2(this::g2); //ok - stuck mref but nominal most specific wins
    1.48 +        m3(this::g2); //ambiguous - different params
    1.49 +    }
    1.50 +}

mercurial