JVM_IR KT-41214 emit PermittedSubclasses on JDK17+

This commit is contained in:
Dmitry Petrov
2021-10-08 09:57:05 +03:00
committed by TeamCityServer
parent dca4a8e722
commit 146f0f4904
41 changed files with 695 additions and 43 deletions
@@ -0,0 +1,21 @@
// IGNORE_BACKEND: JVM
// !LANGUAGE: +JvmPermittedSubclassesAttributeForSealed
// ENABLE_JVM_PREVIEW
// FILE: javaExhaustiveWhenOnKotlinSealedClass.kt
sealed class KS
class KO : KS()
class KK : KS()
fun box(): String =
J.test(KO()) + J.test(KK())
// FILE: J.java
public class J {
public static String test(KS ks) {
return switch (ks) {
case KO ko -> "O";
case KK kk -> "K";
};
}
}
@@ -0,0 +1,29 @@
// IGNORE_BACKEND: JVM
// WITH_REFLECT
// !LANGUAGE: +JvmPermittedSubclassesAttributeForSealed
sealed class Base
class O : Base()
class K : Base()
sealed interface IBase
class X : IBase
class Y : IBase
fun box(): String {
val cBase = Base::class.java
if (!cBase.isSealed) return "Error: Base is not sealed"
val pBase = cBase.permittedSubclasses.mapTo(HashSet()) { it.simpleName ?: "???" }
if (pBase != setOf("O", "K")) {
return "Failed: $pBase"
}
val cIBase = IBase::class.java
if (!cIBase.isSealed) return "Error: IBase is not sealed"
val pIBase = cIBase.permittedSubclasses.mapTo(HashSet()) { it.simpleName ?: "???" }
if (pIBase != setOf("X", "Y")) {
return "Failed: $pIBase"
}
return "OK"
}