[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 FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
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
|
||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||
@@ -35226,6 +35232,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
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
|
||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("flexibleSealedInSubject.kt")
|
||||
public void testFlexibleSealedInSubject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/testsWithJava17/sealedClasses/flexibleSealedInSubject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaSealedClassExhaustiveness.kt")
|
||||
public void testJavaSealedClassExhaustiveness() throws Exception {
|
||||
@@ -35322,6 +35328,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
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
|
||||
@TestMetadata("intersectionExhaustivenessComplex.kt")
|
||||
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.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isBooleanOrNullableBoolean
|
||||
import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible
|
||||
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
||||
|
||||
object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
|
||||
@@ -45,7 +46,7 @@ object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
|
||||
reporter.reportOn(source, FirErrors.NO_ELSE_IN_WHEN, whenExpression.missingCases, context)
|
||||
}
|
||||
} 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 kind = when {
|
||||
subjectClassSymbol.modality == Modality.SEALED -> AlgebraicTypeKind.Sealed
|
||||
|
||||
Reference in New Issue
Block a user