lambda/method refs: inference exception variables (initial)

This commit is contained in:
anna
2013-02-27 12:19:40 +01:00
parent 66a91b4180
commit 6308a651a2
6 changed files with 172 additions and 0 deletions
@@ -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>
}
}
@@ -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);
}
}
@@ -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>
}
}
@@ -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>);
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import org.jetbrains.annotations.NonNls;
public class ExceptionVariablesInferenceTest extends LightDaemonAnalyzerTestCase {
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/exceptions";
public void testUnboundExceptions() throws Exception {
doTest();
}
public void testNotThrownLambdaBodyReferencedMethod() throws Exception {
doTest();
}
public void testNotThrownLambdaBodyReferencedMethodContradictBounds() throws Exception {
doTest();
}
public void testLambdaParamExceptionVariable() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}
private void doTest(final boolean checkWarnings) throws Exception {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false);
}
}