[FIR] Unwrap flexible types in when exhaustiveness checker
^KT-56942 Fixed
This commit is contained in:
committed by
Space Team
parent
01c670194a
commit
0bbc61f459
+12
@@ -32915,6 +32915,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleSealedInSubject.kt")
|
||||||
|
public void testFlexibleSealedInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses/flexibleSealedInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||||
@@ -35226,6 +35232,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleEnumInSubject.kt")
|
||||||
|
public void testFlexibleEnumInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/flexibleEnumInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||||
public void testIntersectionExhaustivenessComplex() throws Exception {
|
public void testIntersectionExhaustivenessComplex() throws Exception {
|
||||||
|
|||||||
+12
@@ -32915,6 +32915,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleSealedInSubject.kt")
|
||||||
|
public void testFlexibleSealedInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses/flexibleSealedInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||||
@@ -35226,6 +35232,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleEnumInSubject.kt")
|
||||||
|
public void testFlexibleEnumInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/flexibleEnumInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||||
public void testIntersectionExhaustivenessComplex() throws Exception {
|
public void testIntersectionExhaustivenessComplex() throws Exception {
|
||||||
|
|||||||
+12
@@ -33011,6 +33011,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleSealedInSubject.kt")
|
||||||
|
public void testFlexibleSealedInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses/flexibleSealedInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||||
@@ -35322,6 +35328,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleEnumInSubject.kt")
|
||||||
|
public void testFlexibleEnumInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/flexibleEnumInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||||
public void testIntersectionExhaustivenessComplex() throws Exception {
|
public void testIntersectionExhaustivenessComplex() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.languageVersionSettings
|
|||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.types.coneType
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
import org.jetbrains.kotlin.fir.types.isBooleanOrNullableBoolean
|
import org.jetbrains.kotlin.fir.types.isBooleanOrNullableBoolean
|
||||||
|
import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible
|
||||||
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
||||||
|
|
||||||
object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
|
object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
|
||||||
@@ -45,7 +46,7 @@ object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
|
|||||||
reporter.reportOn(source, FirErrors.NO_ELSE_IN_WHEN, whenExpression.missingCases, context)
|
reporter.reportOn(source, FirErrors.NO_ELSE_IN_WHEN, whenExpression.missingCases, context)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val subjectType = whenExpression.subject?.typeRef?.coneType ?: return
|
val subjectType = whenExpression.subject?.typeRef?.coneType?.lowerBoundIfFlexible() ?: return
|
||||||
val subjectClassSymbol = subjectType.fullyExpandedType(context.session).toRegularClassSymbol(context.session) ?: return
|
val subjectClassSymbol = subjectType.fullyExpandedType(context.session).toRegularClassSymbol(context.session) ?: return
|
||||||
val kind = when {
|
val kind = when {
|
||||||
subjectClassSymbol.modality == Modality.SEALED -> AlgebraicTypeKind.Sealed
|
subjectClassSymbol.modality == Modality.SEALED -> AlgebraicTypeKind.Sealed
|
||||||
|
|||||||
Vendored
+59
@@ -0,0 +1,59 @@
|
|||||||
|
// ISSUE: KT-56942
|
||||||
|
// FILE: Base.java
|
||||||
|
public sealed class Base permits A, B {
|
||||||
|
public static Base provide() { return new A(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: A.java
|
||||||
|
public final class A extends Base {}
|
||||||
|
|
||||||
|
// FILE: B.java
|
||||||
|
public final class B extends Base {}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun test_0(base: Base) {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (base) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
<!SENSELESS_NULL_IN_WHEN!>null<!> -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_1() {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (Base.provide()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
null -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+59
@@ -0,0 +1,59 @@
|
|||||||
|
// ISSUE: KT-56942
|
||||||
|
// FILE: Base.java
|
||||||
|
public sealed class Base permits A, B {
|
||||||
|
public static Base provide() { return new A(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: A.java
|
||||||
|
public final class A extends Base {}
|
||||||
|
|
||||||
|
// FILE: B.java
|
||||||
|
public final class B extends Base {}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun test_0(base: Base) {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (base) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
<!SENSELESS_NULL_IN_WHEN!>null<!> -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (base) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_1() {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (Base.provide()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
null -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (Base.provide()) {
|
||||||
|
is A -> {}
|
||||||
|
is B -> {}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// ISSUE: KT-56942
|
||||||
|
// FILE: EnumJava.java
|
||||||
|
public enum EnumJava {
|
||||||
|
JAVA_ONE, JAVA_TWO;
|
||||||
|
|
||||||
|
public static EnumJava provide() { return EnumJava.JAVA_ONE; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: EnumProviderJava.java
|
||||||
|
public class EnumProviderJava {
|
||||||
|
public static EnumJava provide() { return EnumJava.JAVA_ONE; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
enum class EnumKotlin {
|
||||||
|
KOTLIN_ONE, KOTLIN_TWO;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun provide(): EnumKotlin = EnumKotlin.KOTLIN_ONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_1(ejp: EnumJava, ekp: EnumKotlin) {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (ejp) {
|
||||||
|
EnumJava.JAVA_ONE -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (ekp) {
|
||||||
|
EnumKotlin.KOTLIN_ONE -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (EnumJava.provide()) {
|
||||||
|
EnumJava.JAVA_ONE -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (EnumKotlin.provide()) {
|
||||||
|
EnumKotlin.KOTLIN_ONE -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test_2(ejp: EnumJava, ekp: EnumKotlin) {
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (ejp) {}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (ekp) {}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (EnumProviderJava.provide()) {}
|
||||||
|
|
||||||
|
<!NO_ELSE_IN_WHEN!>when<!> (EnumKotlin.provide()) {}
|
||||||
|
}
|
||||||
Generated
+12
@@ -33011,6 +33011,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleSealedInSubject.kt")
|
||||||
|
public void testFlexibleSealedInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses/flexibleSealedInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||||
@@ -35322,6 +35328,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
runTest("compiler/testData/diagnostics/tests/when/extractingEntireCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleEnumInSubject.kt")
|
||||||
|
public void testFlexibleEnumInSubject() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/when/flexibleEnumInSubject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||||
public void testIntersectionExhaustivenessComplex() throws Exception {
|
public void testIntersectionExhaustivenessComplex() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user