inference: proper exceptions thrown checks (IDEA-152577)

This commit is contained in:
Anna Kozlova
2016-03-04 12:19:21 +01:00
parent 09e54999ef
commit 8ff49ddc39
3 changed files with 22 additions and 1 deletions

View File

@@ -161,7 +161,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
private static boolean isAddressed(List<PsiType> expectedThrownTypes, PsiType thrownType) {
for (PsiType expectedThrownType : expectedThrownTypes) {
if (TypeConversionUtil.isAssignable(TypeConversionUtil.erasure(thrownType), expectedThrownType)) {
if (TypeConversionUtil.isAssignable(expectedThrownType, thrownType)) {
return true;
}
}

View File

@@ -0,0 +1,17 @@
import java.io.IOException;
class GenericException {
{
applyFunc(t -> throwsException());
}
private static <T, E extends Exception> void applyFunc(CheckedFunction<T, E> function) {}
private static void throwsException() throws Exception {}
interface CheckedFunction<T, E extends Exception> {
void apply(T t) throws E, IOException;
}
}

View File

@@ -63,6 +63,10 @@ public class ConstraintsInferenceMiscTest extends LightDaemonAnalyzerTestCase {
doTest(false);
}
public void testExceptionConstraintsWithProperAndNonProperThrows() throws Exception {
doTest(false);
}
private void doTest(final boolean checkWarnings) {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false);
}