[FE 1.0] Fix reporting of non exhaustive when statement for whens with subject
^KT-48653 Fixed
This commit is contained in:
+12
@@ -32111,6 +32111,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt47922.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_after.kt")
|
||||
public void testKt48653_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_before.kt")
|
||||
public void testKt48653_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9929.kt")
|
||||
public void testKt9929() throws Exception {
|
||||
|
||||
+12
@@ -32111,6 +32111,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt47922.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_after.kt")
|
||||
public void testKt48653_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_before.kt")
|
||||
public void testKt48653_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9929.kt")
|
||||
public void testKt9929() throws Exception {
|
||||
|
||||
+1
-4
@@ -1002,7 +1002,7 @@ class ControlFlowInformationProviderImpl private constructor(
|
||||
trace.report(EXPECT_TYPE_IN_WHEN_WITHOUT_ELSE.on(element, it.typeOfDeclaration))
|
||||
}
|
||||
} else if (subjectExpression != null) {
|
||||
val subjectType = trace.getType(subjectExpression)
|
||||
val subjectType = WhenChecker.whenSubjectType(element, trace.bindingContext)
|
||||
if (elseEntry != null) {
|
||||
if (missingCases.isEmpty() && subjectType != null && !subjectType.isFlexible()) {
|
||||
val subjectClass = subjectType.constructor.declarationDescriptor as? ClassDescriptor
|
||||
@@ -1016,9 +1016,6 @@ class ControlFlowInformationProviderImpl private constructor(
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (!usedAsExpression) {
|
||||
|
||||
}
|
||||
if (!usedAsExpression) {
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.WarnAboutNonExhaustiveWhenOnAlgebraicTypes)) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: +ProhibitNonExhaustiveWhenOnAlgebraicTypes
|
||||
// ISSUE: KT-48653
|
||||
|
||||
sealed class Sealed {
|
||||
object A : Sealed()
|
||||
object B : Sealed()
|
||||
}
|
||||
fun functionReturningSealed(): Sealed = null!!
|
||||
|
||||
fun test_1() {
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (val result = functionReturningSealed()) {
|
||||
is Sealed.A -> {}
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2() {
|
||||
val result2 = functionReturningSealed()
|
||||
<!NO_ELSE_IN_WHEN!>when<!> (result2) {
|
||||
is Sealed.A -> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
public fun functionReturningSealed(): Sealed
|
||||
public fun test_1(): kotlin.Unit
|
||||
public fun test_2(): kotlin.Unit
|
||||
|
||||
public sealed class Sealed {
|
||||
protected constructor Sealed()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public object A : Sealed {
|
||||
private constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public object B : Sealed {
|
||||
private constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: -ProhibitNonExhaustiveWhenOnAlgebraicTypes
|
||||
// ISSUE: KT-48653
|
||||
|
||||
sealed class Sealed {
|
||||
object A : Sealed()
|
||||
object B : Sealed()
|
||||
}
|
||||
fun functionReturningSealed(): Sealed = null!!
|
||||
|
||||
fun test_1() {
|
||||
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (val result = functionReturningSealed()) {
|
||||
is Sealed.A -> {}
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2() {
|
||||
val result2 = functionReturningSealed()
|
||||
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (result2) {
|
||||
is Sealed.A -> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
public fun functionReturningSealed(): Sealed
|
||||
public fun test_1(): kotlin.Unit
|
||||
public fun test_2(): kotlin.Unit
|
||||
|
||||
public sealed class Sealed {
|
||||
protected constructor Sealed()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public object A : Sealed {
|
||||
private constructor A()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public object B : Sealed {
|
||||
private constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Generated
+12
@@ -32207,6 +32207,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt47922.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_after.kt")
|
||||
public void testKt48653_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_before.kt")
|
||||
public void testKt48653_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9929.kt")
|
||||
public void testKt9929() throws Exception {
|
||||
|
||||
+12
@@ -32111,6 +32111,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt47922.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_after.kt")
|
||||
public void testKt48653_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48653_before.kt")
|
||||
public void testKt48653_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/when/kt48653_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt9929.kt")
|
||||
public void testKt9929() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user