Retain data flow info after conditions in do-while statements
This commit is contained in:
+2
-2
@@ -236,10 +236,10 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context, context.trace);
|
||||
}
|
||||
JetExpression condition = expression.getCondition();
|
||||
checkCondition(conditionScope, condition, context);
|
||||
DataFlowInfo conditionDataFlowInfo = checkCondition(conditionScope, condition, context);
|
||||
DataFlowInfo dataFlowInfo;
|
||||
if (!containsBreak(expression, context)) {
|
||||
dataFlowInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, context);
|
||||
dataFlowInfo = DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, context).and(conditionDataFlowInfo);
|
||||
}
|
||||
else {
|
||||
dataFlowInfo = context.dataFlowInfo;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
fun simpleDoWhile(x: Int?, var y: Int) {
|
||||
do {
|
||||
x : Int?
|
||||
y++
|
||||
} while (x!! == y)
|
||||
x : Int
|
||||
}
|
||||
|
||||
fun doWhileWithBreak(x: Int?, var y: Int) {
|
||||
do {
|
||||
x : Int?
|
||||
y++
|
||||
if (y > 0) break
|
||||
} while (x!! == y)
|
||||
<!TYPE_MISMATCH!>x<!> : Int
|
||||
}
|
||||
@@ -1211,6 +1211,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DoWhileCondition.kt")
|
||||
public void testDoWhileCondition() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/DoWhileCondition.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Elvis.kt")
|
||||
public void testElvis() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/Elvis.kt");
|
||||
|
||||
Reference in New Issue
Block a user