Data flow analysis: unnecessary assignment removed (related to complex expressions)
This commit is contained in:
+2
-11
@@ -172,14 +172,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (innerExpression == null) {
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
KotlinTypeInfo result = facade.getTypeInfo(innerExpression, context.replaceScope(context.scope));
|
||||
KotlinType resultType = result.getType();
|
||||
if (resultType != null) {
|
||||
DataFlowValue innerValue = DataFlowValueFactory.createDataFlowValue(innerExpression, resultType, context);
|
||||
DataFlowValue resultValue = DataFlowValueFactory.createDataFlowValue(expression, resultType, context);
|
||||
result = result.replaceDataFlowInfo(result.getDataFlowInfo().assign(resultValue, innerValue));
|
||||
}
|
||||
return result;
|
||||
return facade.getTypeInfo(innerExpression, context.replaceScope(context.scope));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1235,10 +1228,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
DataFlowValue resultValue = DataFlowValueFactory.createDataFlowValue(expression, type, context);
|
||||
dataFlowInfo = dataFlowInfo.assign(resultValue, leftValue).disequate(resultValue, nullValue);
|
||||
dataFlowInfo = dataFlowInfo.disequate(resultValue, nullValue);
|
||||
if (!jumpInRight) {
|
||||
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rightType, context);
|
||||
rightDataFlowInfo = rightDataFlowInfo.assign(resultValue, rightValue);
|
||||
dataFlowInfo = dataFlowInfo.or(rightDataFlowInfo);
|
||||
}
|
||||
}
|
||||
|
||||
-7
@@ -154,13 +154,6 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
KotlinType elseType = elseTypeInfo.getType();
|
||||
DataFlowInfo thenDataFlowInfo = thenTypeInfo.getDataFlowInfo();
|
||||
DataFlowInfo elseDataFlowInfo = elseTypeInfo.getDataFlowInfo();
|
||||
if (resultType != null && thenType != null && elseType != null) {
|
||||
DataFlowValue resultValue = DataFlowValueFactory.createDataFlowValue(ifExpression, resultType, context);
|
||||
DataFlowValue thenValue = DataFlowValueFactory.createDataFlowValue(thenBranch, thenType, context);
|
||||
thenDataFlowInfo = thenDataFlowInfo.assign(resultValue, thenValue);
|
||||
DataFlowValue elseValue = DataFlowValueFactory.createDataFlowValue(elseBranch, elseType, context);
|
||||
elseDataFlowInfo = elseDataFlowInfo.assign(resultValue, elseValue);
|
||||
}
|
||||
|
||||
loopBreakContinuePossible |= thenTypeInfo.getJumpOutPossible() || elseTypeInfo.getJumpOutPossible();
|
||||
|
||||
|
||||
-7
@@ -246,13 +246,6 @@ public class ExpressionTypingServices {
|
||||
result = getTypeOfLastExpressionInBlock(
|
||||
statementExpression, newContext.replaceExpectedType(context.expectedType), coercionStrategyForLastExpression,
|
||||
blockLevelVisitor);
|
||||
if (result.getType() != null && statementExpression.getParent() instanceof KtBlockExpression) {
|
||||
DataFlowValue lastExpressionValue = DataFlowValueFactory.createDataFlowValue(
|
||||
statementExpression, result.getType(), context);
|
||||
DataFlowValue blockExpressionValue = DataFlowValueFactory.createDataFlowValue(
|
||||
(KtBlockExpression) statementExpression.getParent(), result.getType(), context);
|
||||
result = result.replaceDataFlowInfo(result.getDataFlowInfo().assign(blockExpressionValue, lastExpressionValue));
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = blockLevelVisitor
|
||||
|
||||
+3
-13
@@ -86,10 +86,8 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
|
||||
|
||||
val dataFlowInfoForEntries = analyzeConditionsInWhenEntries(expression, contextAfterSubject, subjectDataFlowValue, subjectType)
|
||||
val whenReturnType = inferTypeForWhenExpression(expression, contextWithExpectedType, contextAfterSubject, dataFlowInfoForEntries)
|
||||
val whenResultValue = whenReturnType?.let { DataFlowValueFactory.createDataFlowValue(expression, it, contextAfterSubject) }
|
||||
|
||||
val branchesTypeInfo =
|
||||
joinWhenExpressionBranches(expression, contextAfterSubject, whenReturnType, jumpOutPossibleInSubject, whenResultValue)
|
||||
val branchesTypeInfo = joinWhenExpressionBranches(expression, contextAfterSubject, whenReturnType, jumpOutPossibleInSubject)
|
||||
|
||||
val isExhaustive = WhenChecker.isWhenExhaustive(expression, trace)
|
||||
|
||||
@@ -174,8 +172,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
|
||||
expression: KtWhenExpression,
|
||||
contextAfterSubject: ExpressionTypingContext,
|
||||
resultType: KotlinType?,
|
||||
jumpOutPossibleInSubject: Boolean,
|
||||
whenResultValue: DataFlowValue?
|
||||
jumpOutPossibleInSubject: Boolean
|
||||
): KotlinTypeInfo {
|
||||
val bindingContext = contextAfterSubject.trace.bindingContext
|
||||
|
||||
@@ -192,14 +189,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
|
||||
errorTypeExistInBranch = true
|
||||
}
|
||||
|
||||
val entryDataFlowInfo =
|
||||
if (whenResultValue != null && entryType != null) {
|
||||
val entryValue = DataFlowValueFactory.createDataFlowValue(entryExpression, entryType, contextAfterSubject)
|
||||
entryTypeInfo.dataFlowInfo.assign(whenResultValue, entryValue)
|
||||
}
|
||||
else {
|
||||
entryTypeInfo.dataFlowInfo
|
||||
}
|
||||
val entryDataFlowInfo = entryTypeInfo.dataFlowInfo
|
||||
|
||||
currentDataFlowInfo =
|
||||
if (entryType != null && KotlinBuiltIns.isNothing(entryType))
|
||||
|
||||
Reference in New Issue
Block a user