Pass DataFlowInfo through when-conditions
This commit is contained in:
+8
-4
@@ -116,9 +116,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (newDataFlowInfo == null) {
|
||||
newDataFlowInfo = context.dataFlowInfo;
|
||||
}
|
||||
else {
|
||||
newDataFlowInfo = newDataFlowInfo.and(context.dataFlowInfo);
|
||||
}
|
||||
}
|
||||
JetExpression bodyExpression = whenEntry.getExpression();
|
||||
if (bodyExpression != null) {
|
||||
@@ -259,14 +256,21 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetExpression expression = pattern.getExpression();
|
||||
if (expression == null) return;
|
||||
JetType type = facade.getTypeInfo(expression, context.replaceScope(scopeToExtend)).getType();
|
||||
if (type == null) return;
|
||||
if (conditionExpected) {
|
||||
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
|
||||
if (type != null && !JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
|
||||
if (!JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
|
||||
}
|
||||
return;
|
||||
}
|
||||
checkTypeCompatibility(type, subjectType, pattern);
|
||||
DataFlowInfo dataFlowInfo = context.dataFlowInfo;
|
||||
DataFlowValue expressionDataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, type, context.trace.getBindingContext());
|
||||
for (DataFlowValue subjectVariable : subjectVariables) {
|
||||
dataFlowInfo = dataFlowInfo.equate(subjectVariable, expressionDataFlowValue);
|
||||
}
|
||||
result.set(dataFlowInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ fun foo() {
|
||||
}
|
||||
|
||||
when (x) {
|
||||
0 -> { if (x == null) return }
|
||||
0 -> { if (<!SENSELESS_COMPARISON!>x == null<!>) return }
|
||||
else -> { if (x == null) return }
|
||||
}
|
||||
bar(x)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun set(<!UNUSED_PARAMETER!>key<!> : String, <!UNUSED_PARAMETER!>value<!> : String) {
|
||||
val a : String? = ""
|
||||
when (a) {
|
||||
"" -> a<!UNSAFE_CALL!>.<!>get(0)
|
||||
"" -> a.get(0)
|
||||
is String, is Any -> a.compareTo("")
|
||||
else -> a.toString()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun set(<warning>key</warning> : String, <warning>value</warning> : String) {
|
||||
val a : String? = ""
|
||||
when (a) {
|
||||
"" -> a<error>.</error>get(0)
|
||||
"" -> a.get(0)
|
||||
is String, is Any -> a.compareTo("")
|
||||
else -> a.toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user