Thu, 12 Nov 2015 21:20:49 +0000
8066974: Compiler doesn't infer method's generic type information in lambda body
Summary: Add logic to avoid post-inference triggers on temporarty AST types
Reviewed-by: vromero
mcimadamore@3001 | 1 | /* |
mcimadamore@3001 | 2 | * @test /nodynamiccopyright/ |
mcimadamore@3001 | 3 | * @bug 8066974 |
mcimadamore@3001 | 4 | * @summary Compiler doesn't infer method's generic type information in lambda body |
mcimadamore@3001 | 5 | * @compile/fail/ref=T8066974.out -XDrawDiagnostics T8066974.java |
mcimadamore@3001 | 6 | */ |
mcimadamore@3001 | 7 | class T8066974 { |
mcimadamore@3001 | 8 | static class Throwing<E extends Throwable> { } |
mcimadamore@3001 | 9 | static class RuntimeThrowing extends Throwing<RuntimeException> { } |
mcimadamore@3001 | 10 | static class CheckedThrowing extends Throwing<Exception> { } |
mcimadamore@3001 | 11 | |
mcimadamore@3001 | 12 | interface Parameter { |
mcimadamore@3001 | 13 | <E extends Throwable> Object m(Throwing<E> tw) throws E; |
mcimadamore@3001 | 14 | } |
mcimadamore@3001 | 15 | |
mcimadamore@3001 | 16 | interface Mapper<R> { |
mcimadamore@3001 | 17 | R m(Parameter p); |
mcimadamore@3001 | 18 | } |
mcimadamore@3001 | 19 | |
mcimadamore@3001 | 20 | <Z> Z map(Mapper<Z> mz) { return null; } |
mcimadamore@3001 | 21 | |
mcimadamore@3001 | 22 | <Z extends Throwable> Mapper<Throwing<Z>> mapper(Throwing<Z> tz) throws Z { return null; } |
mcimadamore@3001 | 23 | |
mcimadamore@3001 | 24 | static class ThrowingMapper<X extends Throwable> implements Mapper<Throwing<X>> { |
mcimadamore@3001 | 25 | ThrowingMapper(Throwing<X> arg) throws X { } |
mcimadamore@3001 | 26 | |
mcimadamore@3001 | 27 | @Override |
mcimadamore@3001 | 28 | public Throwing<X> m(Parameter p) { |
mcimadamore@3001 | 29 | return null; |
mcimadamore@3001 | 30 | } |
mcimadamore@3001 | 31 | } |
mcimadamore@3001 | 32 | |
mcimadamore@3001 | 33 | void testRuntime(RuntimeThrowing rt) { |
mcimadamore@3001 | 34 | map(p->p.m(rt)); |
mcimadamore@3001 | 35 | map(mapper(rt)); |
mcimadamore@3001 | 36 | map(new ThrowingMapper<>(rt)); |
mcimadamore@3001 | 37 | } |
mcimadamore@3001 | 38 | |
mcimadamore@3001 | 39 | void testChecked(CheckedThrowing ct) { |
mcimadamore@3001 | 40 | map(p->p.m(ct)); |
mcimadamore@3001 | 41 | map(mapper(ct)); |
mcimadamore@3001 | 42 | map(new ThrowingMapper<>(ct)); |
mcimadamore@3001 | 43 | } |
mcimadamore@3001 | 44 | } |