[FIR] Unwrap flexible types in when exhaustiveness checker

^KT-56942 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-02-24 12:38:55 +02:00
committed by Space Team
parent 01c670194a
commit 0bbc61f459
8 changed files with 219 additions and 1 deletions
@@ -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 -> {}
}
}
@@ -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 -> {}
}
}