FIR: allow no else branch for when on Nothing(?)
This commit is contained in:
committed by
teamcityserver
parent
e242ad955b
commit
f737d8002e
+6
@@ -32089,6 +32089,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whenOnNothing.kt")
|
||||||
|
public void testWhenOnNothing() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/whenOnNothing.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WhenTypeDisjunctions.kt")
|
@TestMetadata("WhenTypeDisjunctions.kt")
|
||||||
public void testWhenTypeDisjunctions() throws Exception {
|
public void testWhenTypeDisjunctions() throws Exception {
|
||||||
|
|||||||
+6
@@ -32089,6 +32089,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whenOnNothing.kt")
|
||||||
|
public void testWhenOnNothing() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/whenOnNothing.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WhenTypeDisjunctions.kt")
|
@TestMetadata("WhenTypeDisjunctions.kt")
|
||||||
public void testWhenTypeDisjunctions() throws Exception {
|
public void testWhenTypeDisjunctions() throws Exception {
|
||||||
|
|||||||
+20
-2
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
import org.jetbrains.kotlin.diagnostics.WhenMissingCase
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.FirEnumEntry
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.getSealedClassInheritors
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.collectEnumEntries
|
import org.jetbrains.kotlin.fir.declarations.utils.collectEnumEntries
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
@@ -33,7 +35,8 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe
|
|||||||
private val exhaustivenessCheckers = listOf(
|
private val exhaustivenessCheckers = listOf(
|
||||||
WhenOnBooleanExhaustivenessChecker,
|
WhenOnBooleanExhaustivenessChecker,
|
||||||
WhenOnEnumExhaustivenessChecker,
|
WhenOnEnumExhaustivenessChecker,
|
||||||
WhenOnSealedClassExhaustivenessChecker
|
WhenOnSealedClassExhaustivenessChecker,
|
||||||
|
WhenOnNothingExhaustivenessChecker
|
||||||
)
|
)
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
@@ -389,3 +392,18 @@ private object WhenOnSealedClassExhaustivenessChecker : WhenExhaustivenessChecke
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object WhenOnNothingExhaustivenessChecker : WhenExhaustivenessChecker() {
|
||||||
|
override fun isApplicable(subjectType: ConeKotlinType, session: FirSession): Boolean {
|
||||||
|
return subjectType.isNullableNothing || subjectType.isNothing
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun computeMissingCases(
|
||||||
|
whenExpression: FirWhenExpression,
|
||||||
|
subjectType: ConeKotlinType,
|
||||||
|
session: FirSession,
|
||||||
|
destination: MutableCollection<WhenMissingCase>
|
||||||
|
) {
|
||||||
|
// Nothing has no branches. The null case for `Nothing?` is handled by WhenOnNullableExhaustivenessChecker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// !DIAGNOSTICS: -UNREACHABLE_CODE
|
||||||
|
|
||||||
|
// exhaustive
|
||||||
|
fun test1(n: Nothing) = when (n) { }
|
||||||
|
fun test2(n: Nothing?) = when (n) {
|
||||||
|
null -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// not exhaustive
|
||||||
|
fun test3(n: Nothing?) = <!NO_ELSE_IN_WHEN!>when<!> (n) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// !DIAGNOSTICS: -UNREACHABLE_CODE
|
||||||
|
|
||||||
|
// exhaustive
|
||||||
|
fun test1(n: Nothing) = when (n) { }
|
||||||
|
fun test2(n: Nothing?) = <!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_CONSTANT!>n<!>) {
|
||||||
|
null -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// not exhaustive
|
||||||
|
fun test3(n: Nothing?) = <!NO_ELSE_IN_WHEN!>when<!> (<!DEBUG_INFO_CONSTANT!>n<!>) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(/*0*/ n: kotlin.Nothing, /*1*/ nn: kotlin.Nothing?): kotlin.Unit
|
||||||
Generated
+6
@@ -32185,6 +32185,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whenOnNothing.kt")
|
||||||
|
public void testWhenOnNothing() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/whenOnNothing.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WhenTypeDisjunctions.kt")
|
@TestMetadata("WhenTypeDisjunctions.kt")
|
||||||
public void testWhenTypeDisjunctions() throws Exception {
|
public void testWhenTypeDisjunctions() throws Exception {
|
||||||
|
|||||||
+6
@@ -32089,6 +32089,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
runTest("compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("whenOnNothing.kt")
|
||||||
|
public void testWhenOnNothing() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/whenOnNothing.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("WhenTypeDisjunctions.kt")
|
@TestMetadata("WhenTypeDisjunctions.kt")
|
||||||
public void testWhenTypeDisjunctions() throws Exception {
|
public void testWhenTypeDisjunctions() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user