test/tools/javac/lambda/8066974/T8066974.java

changeset 3001
dcd12fa5b58a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/8066974/T8066974.java	Thu Nov 12 21:20:49 2015 +0000
     1.3 @@ -0,0 +1,44 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 8066974
     1.7 + * @summary Compiler doesn't infer method's generic type information in lambda body
     1.8 + * @compile/fail/ref=T8066974.out -XDrawDiagnostics T8066974.java
     1.9 + */
    1.10 +class T8066974 {
    1.11 +    static class Throwing<E extends Throwable> { }
    1.12 +    static class RuntimeThrowing extends Throwing<RuntimeException> { }
    1.13 +    static class CheckedThrowing extends Throwing<Exception> { }
    1.14 +
    1.15 +    interface Parameter {
    1.16 +        <E extends Throwable> Object m(Throwing<E> tw) throws E;
    1.17 +    }
    1.18 +
    1.19 +    interface Mapper<R> {
    1.20 +        R m(Parameter p);
    1.21 +    }
    1.22 +
    1.23 +    <Z> Z map(Mapper<Z> mz) { return null; }
    1.24 +
    1.25 +    <Z extends Throwable> Mapper<Throwing<Z>> mapper(Throwing<Z> tz) throws Z { return null; }
    1.26 +
    1.27 +    static class ThrowingMapper<X extends Throwable> implements Mapper<Throwing<X>> {
    1.28 +        ThrowingMapper(Throwing<X> arg) throws X { }
    1.29 +
    1.30 +        @Override
    1.31 +        public Throwing<X> m(Parameter p) {
    1.32 +        return null;
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36 +    void testRuntime(RuntimeThrowing rt) {
    1.37 +        map(p->p.m(rt));
    1.38 +        map(mapper(rt));
    1.39 +        map(new ThrowingMapper<>(rt));
    1.40 +    }
    1.41 +
    1.42 +    void testChecked(CheckedThrowing ct) {
    1.43 +        map(p->p.m(ct));
    1.44 +        map(mapper(ct));
    1.45 +        map(new ThrowingMapper<>(ct));
    1.46 +    }
    1.47 +}

mercurial