Files
kotlin-fork/compiler/testData/codegen/boxModernJdk/testsWithJava17/sealed/sealedJavaInterfaceViaKotlinReflection.kt
T
Ilya Chernikov 5d6e2b57a7 Sort sealed class inheritors to ensure reproducible builds with IC
without this sorting the inheritors field in the metadata may depend on
whether some inheritors are compiled in the IC round or not.
2022-03-30 08:35:30 +00:00

22 lines
587 B
Kotlin
Vendored

// WITH_REFLECT
// FILE: Base.java
public sealed interface Base permits O, K {}
// FILE: O.java
public non-sealed interface O extends Base {}
// FILE: K.java
public non-sealed interface K extends Base {}
// FILE: main.kt
fun box(): String {
val klass = Base::class
if (!klass.isSealed) return "Error: Base is not sealed"
if (klass.isAbstract) return "Error: Base is abstract"
return klass.sealedSubclasses.asReversed()
.joinToString("") { it.simpleName ?: "_No name provided_" }
.takeIf { it.isNotBlank() }
?: "_No sealed subclasses found_"
}