[FE, Java resolve] Support inheritors of sealed Java type without permits clause

This fixes a false negative NO_ELSE_IN_WHEN in K2 and incidentally
also fixes a false positive NO_ELSE_IN_WHEN in K1 since the fix is in
the common code.

#KT-62491 Fixed
This commit is contained in:
Kirill Rakhman
2023-10-24 10:00:18 +02:00
committed by Space Team
parent 15d3bf5e25
commit ac203591e5
22 changed files with 291 additions and 21 deletions
@@ -10,11 +10,29 @@ public final class A extends Base {}
// FILE: B.java
public sealed class B extends Base permits B.C, B.D {
public static final class C implements B {}
public static final class C extends B {}
public static non-sealed class D extends B {}
}
// FILE: SameFile.java
public sealed class SameFile {
public static final class A extends SameFile {}
public static sealed class B extends SameFile {
public static final class C extends B {}
public static non-sealed class D extends B {}
}
}
// FILE: SameFileNonSealed.java
public class SameFileNonSealed {
public static final class A extends SameFileNonSealed {}
public static class B extends SameFileNonSealed {
public static final class C extends B {}
public static class D extends B {}
}
}
// FILE: main.kt
fun test_ok_1(base: Base) {
val x = when (base) {
@@ -31,6 +49,21 @@ fun test_ok_2(base: Base) {
}
}
fun test_ok_3(sameFile: SameFile) {
val x = when (sameFile) {
is SameFile.A -> 1
is SameFile.B -> 2
}
}
fun test_ok_4(sameFile: SameFile) {
val x = when (sameFile) {
is SameFile.A -> 1
is SameFile.B.C -> 2
is SameFile.B.D -> 3
}
}
fun test_error_1(base: Base) {
val x = <!NO_ELSE_IN_WHEN!>when<!> (base) {
is A -> 1
@@ -43,3 +76,31 @@ fun test_error_2(base: Base) {
is B.C -> 2
}
}
fun test_error_3(sameFile: SameFile) {
val x = <!NO_ELSE_IN_WHEN!>when<!> (sameFile) {
is SameFile.A -> 1
}
}
fun test_error_4(sameFile: SameFile) {
val x = <!NO_ELSE_IN_WHEN!>when<!> (sameFile) {
is SameFile.A -> 1
is SameFile.B.C -> 2
}
}
fun test_error_5(sameFile: SameFileNonSealed) {
val x = <!NO_ELSE_IN_WHEN!>when<!> (sameFile) {
is SameFileNonSealed.A -> 1
is SameFileNonSealed.B -> 2
}
}
fun test_error_6(sameFile: SameFileNonSealed) {
val x = <!NO_ELSE_IN_WHEN!>when<!> (sameFile) {
is SameFileNonSealed.A -> 1
is SameFileNonSealed.B.C -> 2
is SameFileNonSealed.B.D -> 2
}
}