Analyzing 'when' expression refactoring
collect data flow infos for branch with many conditions
This commit is contained in:
+17
-19
@@ -100,45 +100,43 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
DataFlowInfo elseDataFlowInfo = context.dataFlowInfo;
|
DataFlowInfo elseDataFlowInfo = context.dataFlowInfo;
|
||||||
for (JetWhenEntry whenEntry : expression.getEntries()) {
|
for (JetWhenEntry whenEntry : expression.getEntries()) {
|
||||||
JetWhenCondition[] conditions = whenEntry.getConditions();
|
JetWhenCondition[] conditions = whenEntry.getConditions();
|
||||||
DataFlowInfo newDataFlowInfo;
|
DataFlowInfos infos = null;
|
||||||
WritableScope scopeToExtend;
|
|
||||||
if (whenEntry.isElse()) {
|
if (whenEntry.isElse()) {
|
||||||
scopeToExtend = newWritableScopeImpl(context, "Scope extended in when-else entry");
|
|
||||||
newDataFlowInfo = elseDataFlowInfo;
|
|
||||||
}
|
}
|
||||||
else if (conditions.length == 1) {
|
else if (conditions.length == 1) {
|
||||||
scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
|
|
||||||
newDataFlowInfo = context.dataFlowInfo;
|
|
||||||
JetWhenCondition condition = conditions[0];
|
JetWhenCondition condition = conditions[0];
|
||||||
if (condition != null) {
|
if (condition != null) {
|
||||||
DataFlowInfos infos = checkWhenCondition(
|
infos = checkWhenCondition(
|
||||||
subjectExpression, subjectExpression == null,
|
subjectExpression, subjectExpression == null,
|
||||||
subjectType, condition,
|
subjectType, condition,
|
||||||
context, subjectDataFlowValue);
|
context, subjectDataFlowValue);
|
||||||
newDataFlowInfo = infos.thenInfo;
|
|
||||||
elseDataFlowInfo = elseDataFlowInfo.and(infos.elseInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scopeToExtend = newWritableScopeImpl(context, "pattern matching"); // We don't write to this scope
|
infos = null;
|
||||||
newDataFlowInfo = null;
|
|
||||||
for (JetWhenCondition condition : conditions) {
|
for (JetWhenCondition condition : conditions) {
|
||||||
DataFlowInfos infos = checkWhenCondition(subjectExpression, subjectExpression == null, subjectType, condition,
|
DataFlowInfos conditionInfos = checkWhenCondition(subjectExpression, subjectExpression == null, subjectType, condition,
|
||||||
context, subjectDataFlowValue);
|
context, subjectDataFlowValue);
|
||||||
if (newDataFlowInfo == null) {
|
if (infos != null) {
|
||||||
newDataFlowInfo = infos.thenInfo;
|
infos = new DataFlowInfos(infos.thenInfo.or(conditionInfos.thenInfo), infos.elseInfo.and(conditionInfos.elseInfo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newDataFlowInfo = newDataFlowInfo.or(infos.thenInfo);
|
infos = conditionInfos;
|
||||||
}
|
}
|
||||||
elseDataFlowInfo = elseDataFlowInfo.and(infos.elseInfo);
|
|
||||||
}
|
|
||||||
if (newDataFlowInfo == null) {
|
|
||||||
newDataFlowInfo = context.dataFlowInfo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DataFlowInfo newDataFlowInfo;
|
||||||
|
if (infos == null) {
|
||||||
|
newDataFlowInfo = elseDataFlowInfo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newDataFlowInfo = infos.thenInfo;
|
||||||
|
elseDataFlowInfo = elseDataFlowInfo.and(infos.elseInfo);
|
||||||
|
}
|
||||||
|
|
||||||
JetExpression bodyExpression = whenEntry.getExpression();
|
JetExpression bodyExpression = whenEntry.getExpression();
|
||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
|
WritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
|
||||||
ExpressionTypingContext newContext = contextWithExpectedType
|
ExpressionTypingContext newContext = contextWithExpectedType
|
||||||
.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo).replaceContextDependency(INDEPENDENT);
|
.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo).replaceContextDependency(INDEPENDENT);
|
||||||
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
||||||
|
|||||||
Reference in New Issue
Block a user