JVM_IR KT-41214 emit PermittedSubclasses on JDK17+
This commit is contained in:
committed by
TeamCityServer
parent
dca4a8e722
commit
146f0f4904
+21
@@ -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";
|
||||
};
|
||||
}
|
||||
}
|
||||
+29
@@ -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"
|
||||
}
|
||||
Reference in New Issue
Block a user