Fix bug in try/catch resolution in NI

Bug was presented in a236ad5
This commit is contained in:
Dmitriy Novozhilov
2019-02-18 12:38:36 +03:00
parent 1e4b7e1ef1
commit 5d0074bda5
5 changed files with 44 additions and 2 deletions
@@ -646,7 +646,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
// it is not actually correct way (#KT-28370) of computing context, but it's how was in OI
// Fix of it is breaking change and allowed with NewDataFlowForTryExpressions language feature.
// See [processTryBranchesWithNewDataFlowAlgorithm] function
ExpressionTypingContext tryOutputContext = getCleanedContextFromTryWithAssignmentsToVar(tryExpression, nothingInAllCatchBranches, context);
ExpressionTypingContext tryOutputContext = getCleanedContextFromTryWithAssignmentsToVar(tryExpression, nothingInAllCatchBranches, context)
.replaceExpectedType(NO_EXPECTED_TYPE)
.replaceContextDependency(INDEPENDENT);
KotlinTypeInfo result = TypeInfoFactoryKt.createTypeInfo(resultType, tryOutputContext);
@@ -713,7 +715,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
PreliminaryLoopVisitor catchVisitor = PreliminaryLoopVisitor.visitCatchBlocks(tryExpression);
ExpressionTypingContext catchOutputContextFromAllBranches = tryOutputContext.replaceDataFlowInfo(
catchVisitor.clearDataFlowInfoForAssignedLocalVariables(dataFlowInfoAfterTry, components.languageVersionSettings)
);
).replaceContextDependency(INDEPENDENT).replaceExpectedType(NO_EXPECTED_TYPE);
KotlinTypeInfo finallyTypeInfo = facade.getTypeInfo(finallyBlock, catchOutputContextFromAllBranches);
DataFlowInfo finallyDataFlowInfo = finallyTypeInfo.getDataFlowInfo();
resultDataFlowInfo = finallyDataFlowInfo.and(nonExceptionalTryCatchesOutputInfo);