KT-4310 Check for definite returns

#KT-4310 Fixed
This commit is contained in:
Svetlana Isakova
2013-12-16 20:00:53 +04:00
parent 43cc818506
commit 400e6d3f44
3 changed files with 24 additions and 2 deletions
@@ -270,8 +270,14 @@ public class ControlStructureTypingUtils {
@Override
public Void visitIfExpression(@NotNull JetIfExpression ifExpression, CheckTypeContext c) {
checkExpressionType(ifExpression.getThen(), c);
checkExpressionType(ifExpression.getElse(), c);
JetExpression thenBranch = ifExpression.getThen();
JetExpression elseBranch = ifExpression.getElse();
if (thenBranch == null || elseBranch == null) {
visitExpression(ifExpression, c);
return null;
}
checkExpressionType(thenBranch, c);
checkExpressionType(elseBranch, c);
return null;
}
@@ -0,0 +1,11 @@
package f
fun test(a: Boolean, b: Boolean): Int {
return if(a) {
1
} else {
<!TYPE_MISMATCH!>if (b) {
3
}<!>
} // no error, but must be
}
@@ -1670,6 +1670,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/controlStructures/kt1075.kt");
}
@TestMetadata("kt4310.kt")
public void testKt4310() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlStructures/kt4310.kt");
}
@TestMetadata("kt657.kt")
public void testKt657() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlStructures/kt657.kt");