lambda/method refs: inference exception variables (initial)

This commit is contained in:
anna
2013-02-27 12:16:34 +01:00
parent 66a91b4180
commit 6308a651a2
6 changed files with 172 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
class Test {
interface F<T extends Throwable> {
void _(T t) throws T;
}
<K extends Throwable> void foo(F<K> f) throws K { }
{
foo(<error descr="Cyclic inference">(t)->{}</error>);
<error descr="Unhandled exception: java.lang.ClassNotFoundException">foo((ClassNotFoundException t)->{});</error>
}
}

View File

@@ -0,0 +1,19 @@
class Test {
interface F<T extends Throwable> {
void _() throws T;
}
void m1() { }
void m2() throws NullPointerException{ }
<K extends Throwable> void foo(F<K> f) throws K { }
{
foo(()->{});
foo(()->{throw new NullPointerException();});
foo(this::m1);
foo(this::m2);
}
}

View File

@@ -0,0 +1,10 @@
class Test {
interface F<T extends ClassNotFoundException> {
void _() throws T;
}
<K extends ClassNotFoundException> void foo(F<K> f) throws K { }
{
<error descr="Unhandled exception: K">foo(() -> {});</error>
}
}

View File

@@ -0,0 +1,29 @@
class Test {
interface F<T extends Throwable> {
void _() throws T;
}
void m1() { }
void m2() throws ClassNotFoundException { }
void m3() throws Exception { }
<K extends Throwable> void foo1(F<K> f) throws K { }
<K extends ClassNotFoundException> void foo2(F<K> f) throws K { }
{
<error descr="Inferred type 'java.lang.RuntimeException' for type parameter 'K' is not within its bound; should extend 'java.lang.ClassNotFoundException'">foo2(()->{})</error>;
foo2(()->{ <error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error> });
<error descr="Inferred type 'java.lang.RuntimeException' for type parameter 'K' is not within its bound; should extend 'java.lang.ClassNotFoundException'">foo2(this::m1)</error>;
foo2(<error descr="Unhandled exception: java.lang.ClassNotFoundException">this::m2</error>);
foo1(()->{ <error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error> });
foo1(()->{ <error descr="Unhandled exception: java.lang.Exception">throw new Exception();</error> });
foo1(<error descr="Unhandled exception: java.lang.ClassNotFoundException">this::m2</error>);
foo1(<error descr="Unhandled exception: java.lang.Exception">this::m3</error>);
}
}