KT-10706: do not report IMPLICIT_CAST_TO_ANY on expressions of type Nothing

This commit is contained in:
Dmitry Petrov
2016-01-18 18:42:24 +03:00
parent 5889ba4293
commit 0c52960d7a
4 changed files with 24 additions and 1 deletions
@@ -744,7 +744,8 @@ public class ControlFlowInformationProvider {
for (KtExpression branchExpression : branchExpressions) {
if (branchExpression == null) continue;
KotlinType branchType = trace.getType(branchExpression);
assert branchType != null : "Branch expression type should be non-null";
if (branchType == null) continue;
if (KotlinBuiltIns.isNothing(branchType)) continue;
trace.report(IMPLICIT_CAST_TO_ANY.on(getResultingExpression(branchExpression), branchType, expressionType));
}
}
@@ -0,0 +1,12 @@
fun TODO(): Nothing = null!!
fun fn(c: Char?): Any? =
if (c == null) TODO()
else when (<!DEBUG_INFO_SMARTCAST!>c<!>) {
'a' -> when (<!DEBUG_INFO_SMARTCAST!>c<!>) {
'B' -> <!IMPLICIT_CAST_TO_ANY!>1<!>
'C' -> <!IMPLICIT_CAST_TO_ANY!>"sdf"<!>
else -> TODO()
}
else -> TODO()
}
@@ -0,0 +1,4 @@
package
public fun TODO(): kotlin.Nothing
public fun fn(/*0*/ c: kotlin.Char?): kotlin.Any?
@@ -3360,6 +3360,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt10706.kt")
public void testKt10706() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/kt10706.kt");
doTest(fileName);
}
@TestMetadata("kt1075.kt")
public void testKt1075() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/kt1075.kt");