[AA] Add diagnostics tests for sealed classes/interfaces

- KT-62895 cannot be reproduced on the Analysis API side. Still, it is
  useful to add tests here for better coverage in the future.
- The reason is likely that Analysis API tests specifically use
  `SealedClassesInheritorsCaclulatorPreAnalysisHandler` to compute
  sealed class inheritors (which are usually the breaking point for
  problems in `when` exhaustiveness checking), so the tests do not use
  the production implementation. See KT-64505 for future work on this
  problem.

^KT-62895
This commit is contained in:
Marco Pennekamp
2023-12-21 11:21:17 +01:00
committed by Space Team
parent 51f1e31cce
commit eabbe21b66
31 changed files with 642 additions and 0 deletions
@@ -0,0 +1,18 @@
// IGNORE_FE10
// KT-64503
// MODULE: dependency
// FILE: MySealedClass.kt
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
// MODULE: main(dependency)
// FILE: main.kt
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1,17 @@
// IGNORE_FE10
// KT-64503
// MODULE: dependency
// FILE: MySealedClass.kt
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
// MODULE: main(dependency)
// FILE: main.kt
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (14,12) - (16,6)
NO_ELSE_IN_WHEN text ranges: [(109,113)]
PSI: KtWhenExpression at (14,12) - (16,6)
@@ -0,0 +1,18 @@
// IGNORE_FE10
// MODULE: lib
// MODULE_KIND: LibraryBinary
// FILE: MySealedClass.kt
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
// MODULE: main(lib)
// FILE: main.kt
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1 @@
Diagnostics from elements:
@@ -0,0 +1,17 @@
// IGNORE_FE10
// MODULE: lib
// MODULE_KIND: LibraryBinary
// FILE: MySealedClass.kt
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
// MODULE: main(lib)
// FILE: main.kt
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (14,12) - (16,6)
NO_ELSE_IN_WHEN text ranges: [(102,106)]
PSI: KtWhenExpression at (14,12) - (16,6)
@@ -0,0 +1,11 @@
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1 @@
Diagnostics from elements:
@@ -0,0 +1,10 @@
sealed class MySealedClass
class OneSealedChild : MySealedClass()
class TwoSealedChild : MySealedClass()
fun testSealed(m: MySealedClass): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (7,12) - (9,6)
NO_ELSE_IN_WHEN text ranges: [(161,165)]
PSI: KtWhenExpression at (7,12) - (9,6)
@@ -0,0 +1,18 @@
// IGNORE_FE10
// KT-64503
// MODULE: dependency
// FILE: MySealedInterface.kt
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
// MODULE: main(dependency)
// FILE: main.kt
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1,17 @@
// IGNORE_FE10
// KT-64503
// MODULE: dependency
// FILE: MySealedInterface.kt
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
// MODULE: main(dependency)
// FILE: main.kt
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (14,12) - (16,6)
NO_ELSE_IN_WHEN text ranges: [(113,117)]
PSI: KtWhenExpression at (14,12) - (16,6)
@@ -0,0 +1,18 @@
// IGNORE_FE10
// MODULE: lib
// MODULE_KIND: LibraryBinary
// FILE: MySealedInterface.kt
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
// MODULE: main(lib)
// FILE: main.kt
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1,17 @@
// IGNORE_FE10
// MODULE: lib
// MODULE_KIND: LibraryBinary
// FILE: MySealedInterface.kt
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
// MODULE: main(lib)
// FILE: main.kt
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (14,12) - (16,6)
NO_ELSE_IN_WHEN text ranges: [(106,110)]
PSI: KtWhenExpression at (14,12) - (16,6)
@@ -0,0 +1,11 @@
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
is TwoSealedChild -> "2"
}
}
@@ -0,0 +1,10 @@
sealed interface MySealedInterface
class OneSealedChild : MySealedInterface
class TwoSealedChild : MySealedInterface
fun testSealed(m: MySealedInterface): String {
return when (m) {
is OneSealedChild -> "1"
}
}
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtWhenExpression at (7,12) - (9,6)
NO_ELSE_IN_WHEN text ranges: [(177,181)]
PSI: KtWhenExpression at (7,12) - (9,6)