From 0c52960d7af53e8ae7e6e8d41cd03d89bf7bd074 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 18 Jan 2016 18:42:24 +0300 Subject: [PATCH] KT-10706: do not report IMPLICIT_CAST_TO_ANY on expressions of type Nothing --- .../kotlin/cfg/ControlFlowInformationProvider.java | 3 ++- .../diagnostics/tests/controlStructures/kt10706.kt | 12 ++++++++++++ .../diagnostics/tests/controlStructures/kt10706.txt | 4 ++++ .../kotlin/checkers/DiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt10706.kt create mode 100644 compiler/testData/diagnostics/tests/controlStructures/kt10706.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.java index 19a2fc2bfbd..fe6d59eec93 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.java @@ -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)); } } diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10706.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10706.kt new file mode 100644 index 00000000000..3f742d21165 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10706.kt @@ -0,0 +1,12 @@ +fun TODO(): Nothing = null!! + +fun fn(c: Char?): Any? = + if (c == null) TODO() + else when (c) { + 'a' -> when (c) { + 'B' -> 1 + 'C' -> "sdf" + else -> TODO() + } + else -> TODO() + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10706.txt b/compiler/testData/diagnostics/tests/controlStructures/kt10706.txt new file mode 100644 index 00000000000..c2d9fd98315 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10706.txt @@ -0,0 +1,4 @@ +package + +public fun TODO(): kotlin.Nothing +public fun fn(/*0*/ c: kotlin.Char?): kotlin.Any? diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d97013c60e5..1722725a684 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -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");