inference: ensure to convert disjunction type to lub (IDEA-150364)

This commit is contained in:
Anna Kozlova
2016-01-14 13:46:55 +01:00
parent 2255d1571f
commit ae64c30eb9
3 changed files with 34 additions and 1 deletions

View File

@@ -50,7 +50,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
return assignmentCompatible;
}
final PsiType exprType = myExpression.getType();
PsiType exprType = myExpression.getType();
if (exprType instanceof PsiLambdaParameterType) {
return false;
@@ -67,6 +67,10 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
}
if (exprType != null && exprType != PsiType.NULL) {
if (exprType instanceof PsiDisjunctionType) {
exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound();
}
constraints.add(new TypeCompatibilityConstraint(myT, exprType));
}
return true;

View File

@@ -0,0 +1,25 @@
class Test {
public static void main(String[] args) throws Exception {
try {
}
catch (Exception | Error e) {
<error descr="Unhandled exception: java.lang.Throwable">throw identity(identity(e));</error>
}
try {
}
catch (Exception | Error e) {
<error descr="Unhandled exception: java.lang.Throwable">throw identity(e);</error>
}
try {
}
catch (Exception | Error e) {
throw e;
}
}
public static <T> T identity(T throwable) {
return throwable;
}
}

View File

@@ -359,6 +359,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testDisjunctionTypes() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}