Retain data flow info after try-finally

This commit is contained in:
Alexander Udalov
2012-11-13 21:17:57 +04:00
parent d629fe2d91
commit ef3e38071c
3 changed files with 31 additions and 3 deletions
@@ -425,18 +425,22 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
} }
} }
} }
DataFlowInfo dataFlowInfo = context.dataFlowInfo;
if (finallyBlock != null) { if (finallyBlock != null) {
facade.getTypeInfo(finallyBlock.getFinalExpression(), context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE)); dataFlowInfo = facade.getTypeInfo(finallyBlock.getFinalExpression(),
context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE)).getDataFlowInfo();
} }
JetType type = facade.getTypeInfo(tryBlock, context).getType(); JetType type = facade.getTypeInfo(tryBlock, context).getType();
if (type != null) { if (type != null) {
types.add(type); types.add(type);
} }
if (types.isEmpty()) { if (types.isEmpty()) {
return JetTypeInfo.create(null, context.dataFlowInfo); return JetTypeInfo.create(null, dataFlowInfo);
} }
else { else {
return JetTypeInfo.create(CommonSupertypes.commonSupertype(types), context.dataFlowInfo); return JetTypeInfo.create(CommonSupertypes.commonSupertype(types), dataFlowInfo);
} }
} }
@@ -0,0 +1,19 @@
fun tryFinally(x: Int?) {
try {
} finally {
x!!
}
x : Int
}
fun tryCatchFinally(x: Int?) {
try {
x!!
} catch (e: Exception) {
x!!
} finally {
<!TYPE_MISMATCH!>x<!> : Int
x!!
}
x : Int
}
@@ -1296,6 +1296,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.kt"); doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.kt");
} }
@TestMetadata("TryFinally.kt")
public void testTryFinally() throws Exception {
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.kt");
}
@TestMetadata("UnaryExpression.kt") @TestMetadata("UnaryExpression.kt")
public void testUnaryExpression() throws Exception { public void testUnaryExpression() throws Exception {
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.kt"); doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.kt");