KT-4310 Check for definite returns
#KT-4310 Fixed
This commit is contained in:
+8
-2
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user