new inference: target type detection according to consequence inference (IDEA-120193)

This commit is contained in:
Anna Kozlova
2014-02-04 12:26:57 +04:00
parent 834e582bd3
commit 8cca960f72
7 changed files with 137 additions and 24 deletions

View File

@@ -29,7 +29,7 @@ public class ConcurrentCollectors {
static <T, K, D, M1 extends Map<K, D>> C<T, M1> groupingBy(F<M1> f,
C<T, D> c,
BiConsumer<M1, T> consumer) {
return new CImpl<>(f, consumer, <error descr="Inferred type 'M1' for type parameter 'M2' is not within its bound; should implement 'ConcurrentCollectors.ConcurrentMap<java.lang.Object,D>'">arg(c.getOp())</error>);
return new CImpl<><error descr="'CImpl(ConcurrentCollectors.F<M1>, ConcurrentCollectors.BiConsumer<M1,T>, ConcurrentCollectors.BiOp<M1>)' in 'ConcurrentCollectors.CImpl' cannot be applied to '(ConcurrentCollectors.F<M1>, ConcurrentCollectors.BiConsumer<M1,T>, ConcurrentCollectors.BiOp<ConcurrentCollectors.ConcurrentMap<java.lang.Object,D>>)'">(f, consumer, arg(c.getOp()))</error>;
}
static <K, V, M2 extends ConcurrentMap<K, V>> BiOp<M2> arg(BiOp<V> op) {

View File

@@ -0,0 +1,72 @@
import java.util.Arrays;
import static java.lang.System.out;
public final class LambdaMain {
public static void main(final String... args) {
for (final A<String, X> a : Arrays.<A<String, X>>asList(new A<String, X>() {
@Override
public String foo(final String ignored)
throws X {
throw new X();
}
}, ignored -> { throw new X(); }))
try {
test(a, "Bob");
} catch (final X x) {
x.printStackTrace();
}
try {
out.println(test(new A<String, X>() {
@Override
public String foo(final String ignored)
throws X {
throw new X();
}
}, "Bob"));
} catch (final Exception e) {
e.printStackTrace();
}
try {
out.println(test(ignored -> { throw new X(); }, "Bob"));
} catch (final Exception e) {
e.printStackTrace();
}
}
static class X
extends Exception {}
interface A<T, E extends Exception> {
T foo(T ignored)
throws E;
}
static <T, E extends Exception> T test(final A<T, E> a, final T ignored)
throws E {
return a.foo(ignored);
}
}
final class LambdaMainTest {
public void main(A<String> a) {
println(test(a));
}
public void println(boolean x) {}
public void println(String x) {}
interface A<T> {
T foo(T ignored) ;
}
static <T> T test (final A<T> a) {
return null;
}
}