Retain data flow info after try-finally
This commit is contained in:
+7
-3
@@ -425,18 +425,22 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataFlowInfo dataFlowInfo = context.dataFlowInfo;
|
||||
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();
|
||||
if (type != null) {
|
||||
types.add(type);
|
||||
}
|
||||
if (types.isEmpty()) {
|
||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||
return JetTypeInfo.create(null, dataFlowInfo);
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
@TestMetadata("TryFinally.kt")
|
||||
public void testTryFinally() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("UnaryExpression.kt")
|
||||
public void testUnaryExpression() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.kt");
|
||||
|
||||
Reference in New Issue
Block a user