Test and implementation for KT-6819. Now when entry condition data flow information is used for subsequent conditions. #KT-6819 Fixed
This commit is contained in:
+3
-1
@@ -143,15 +143,17 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataFlowInfos infos = null;
|
DataFlowInfos infos = null;
|
||||||
|
ExpressionTypingContext contextForCondition = context;
|
||||||
for (JetWhenCondition condition : whenEntry.getConditions()) {
|
for (JetWhenCondition condition : whenEntry.getConditions()) {
|
||||||
DataFlowInfos conditionInfos = checkWhenCondition(subjectExpression, subjectType, condition,
|
DataFlowInfos conditionInfos = checkWhenCondition(subjectExpression, subjectType, condition,
|
||||||
context, subjectDataFlowValue);
|
contextForCondition, subjectDataFlowValue);
|
||||||
if (infos != null) {
|
if (infos != null) {
|
||||||
infos = new DataFlowInfos(infos.thenInfo.or(conditionInfos.thenInfo), infos.elseInfo.and(conditionInfos.elseInfo));
|
infos = new DataFlowInfos(infos.thenInfo.or(conditionInfos.thenInfo), infos.elseInfo.and(conditionInfos.elseInfo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
infos = conditionInfos;
|
infos = conditionInfos;
|
||||||
}
|
}
|
||||||
|
contextForCondition = contextForCondition.replaceDataFlowInfo(conditionInfos.elseInfo);
|
||||||
}
|
}
|
||||||
return infos != null ? infos : new DataFlowInfos(context.dataFlowInfo);
|
return infos != null ? infos : new DataFlowInfos(context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
public fun test(o: String?): Boolean {
|
||||||
|
return when {
|
||||||
|
// Data flow info should propagate from o == null to o.length()
|
||||||
|
o == null, <!DEBUG_INFO_SMARTCAST!>o<!>.length() == 0 -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(/*0*/ o: kotlin.String?): kotlin.Boolean
|
||||||
@@ -11412,6 +11412,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5907var.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt5907var.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt6819.kt")
|
||||||
|
public void testKt6819() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/kt6819.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user