Refactor if expressions resolving
Context without expected type became redundant after synthetic call resolving was added for inference of `if` expression type `isStatement` flag removed, because it was effectively unused
This commit is contained in:
+8
-16
@@ -80,14 +80,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KotlinTypeInfo visitIfExpression(@NotNull KtIfExpression expression, ExpressionTypingContext context) {
|
public KotlinTypeInfo visitIfExpression(@NotNull KtIfExpression ifExpression, ExpressionTypingContext context) {
|
||||||
return visitIfExpression(expression, context, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public KotlinTypeInfo visitIfExpression(KtIfExpression ifExpression, ExpressionTypingContext contextWithExpectedType, boolean isStatement) {
|
|
||||||
components.dataFlowAnalyzer.recordExpectedType(contextWithExpectedType.trace, ifExpression, contextWithExpectedType.expectedType);
|
|
||||||
|
|
||||||
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
|
|
||||||
KtExpression condition = ifExpression.getCondition();
|
KtExpression condition = ifExpression.getCondition();
|
||||||
DataFlowInfo conditionDataFlowInfo = checkCondition(condition, context);
|
DataFlowInfo conditionDataFlowInfo = checkCondition(condition, context);
|
||||||
boolean loopBreakContinuePossibleInCondition = condition != null && containsJumpOutOfLoop(condition, context);
|
boolean loopBreakContinuePossibleInCondition = condition != null && containsJumpOutOfLoop(condition, context);
|
||||||
@@ -103,7 +96,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (elseBranch == null) {
|
if (elseBranch == null) {
|
||||||
if (thenBranch != null) {
|
if (thenBranch != null) {
|
||||||
KotlinTypeInfo result = getTypeInfoWhenOnlyOneBranchIsPresent(
|
KotlinTypeInfo result = getTypeInfoWhenOnlyOneBranchIsPresent(
|
||||||
thenBranch, thenScope, thenInfo, elseInfo, contextWithExpectedType, ifExpression);
|
thenBranch, thenScope, thenInfo, elseInfo, context, ifExpression);
|
||||||
// If jump was possible, take condition check info as the jump info
|
// If jump was possible, take condition check info as the jump info
|
||||||
return result.getJumpOutPossible()
|
return result.getJumpOutPossible()
|
||||||
? result.replaceJumpOutPossible(true).replaceJumpFlowInfo(conditionDataFlowInfo)
|
? result.replaceJumpOutPossible(true).replaceJumpFlowInfo(conditionDataFlowInfo)
|
||||||
@@ -113,7 +106,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
if (thenBranch == null) {
|
if (thenBranch == null) {
|
||||||
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
return getTypeInfoWhenOnlyOneBranchIsPresent(
|
||||||
elseBranch, elseScope, elseInfo, thenInfo, contextWithExpectedType, ifExpression);
|
elseBranch, elseScope, elseInfo, thenInfo, context, ifExpression);
|
||||||
}
|
}
|
||||||
KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(ifExpression, false);
|
KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(ifExpression, false);
|
||||||
KtBlockExpression thenBlock = psiFactory.wrapInABlockWrapper(thenBranch);
|
KtBlockExpression thenBlock = psiFactory.wrapInABlockWrapper(thenBranch);
|
||||||
@@ -124,17 +117,16 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
|
||||||
callForIf, ResolveConstruct.IF, Lists.newArrayList("thenBranch", "elseBranch"),
|
callForIf, ResolveConstruct.IF, Lists.newArrayList("thenBranch", "elseBranch"),
|
||||||
Lists.newArrayList(false, false),
|
Lists.newArrayList(false, false),
|
||||||
contextWithExpectedType, dataFlowInfoForArguments);
|
context, dataFlowInfoForArguments);
|
||||||
|
|
||||||
return processBranches(
|
return processIfBranches(
|
||||||
ifExpression, contextWithExpectedType, context, conditionDataFlowInfo,
|
ifExpression, context, conditionDataFlowInfo,
|
||||||
loopBreakContinuePossibleInCondition, elseBranch, thenBranch, resolvedCall);
|
loopBreakContinuePossibleInCondition, elseBranch, thenBranch, resolvedCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private KotlinTypeInfo processBranches(
|
private KotlinTypeInfo processIfBranches(
|
||||||
KtIfExpression ifExpression,
|
KtIfExpression ifExpression,
|
||||||
ExpressionTypingContext contextWithExpectedType,
|
|
||||||
ExpressionTypingContext context,
|
ExpressionTypingContext context,
|
||||||
DataFlowInfo conditionDataFlowInfo,
|
DataFlowInfo conditionDataFlowInfo,
|
||||||
boolean loopBreakContinuePossibleInCondition,
|
boolean loopBreakContinuePossibleInCondition,
|
||||||
@@ -206,7 +198,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
// If break or continue was possible, take condition check info as the jump info
|
// If break or continue was possible, take condition check info as the jump info
|
||||||
return TypeInfoFactoryKt.createTypeInfo(
|
return TypeInfoFactoryKt.createTypeInfo(
|
||||||
components.dataFlowAnalyzer.checkType(resultType, ifExpression, contextWithExpectedType),
|
components.dataFlowAnalyzer.checkType(resultType, ifExpression, context),
|
||||||
resultDataFlowInfo, loopBreakContinuePossible,
|
resultDataFlowInfo, loopBreakContinuePossible,
|
||||||
loopBreakContinuePossibleInCondition ? context.dataFlowInfo : conditionDataFlowInfo);
|
loopBreakContinuePossibleInCondition ? context.dataFlowInfo : conditionDataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -403,7 +403,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KotlinTypeInfo visitIfExpression(@NotNull KtIfExpression expression, ExpressionTypingContext context) {
|
public KotlinTypeInfo visitIfExpression(@NotNull KtIfExpression expression, ExpressionTypingContext context) {
|
||||||
return controlStructures.visitIfExpression(expression, context, true);
|
return controlStructures.visitIfExpression(expression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user