mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-11 15:53:46 +00:00
Introduce MetadataSource as a way to store the original descriptor for any element (before any lowerings) and maintain it until the end of the codegen where it's used in generating the metadata. Note that JVM signatures written to the metadata are formed from the _resulting_ generated elements, not by mapping the original descriptors. Some corner cases are not supported yet, namely properties declared in companion objects, synthetic methods for property annotations, JvmPackageName, etc. #KT-29119 Fixed
41 lines
1.2 KiB
Kotlin
Vendored
41 lines
1.2 KiB
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
// WITH_REFLECT
|
|
|
|
import kotlin.reflect.KClass
|
|
import kotlin.test.assertEquals
|
|
|
|
// --
|
|
|
|
sealed class SealedClassWithTopLevelSubclasses {
|
|
class NotASealedSubclass : TL2()
|
|
}
|
|
object TL1 : SealedClassWithTopLevelSubclasses()
|
|
open class TL2 : SealedClassWithTopLevelSubclasses()
|
|
|
|
// --
|
|
|
|
sealed class SealedClassWithNestedSubclasses {
|
|
data class N1(val x: Unit) : SealedClassWithNestedSubclasses()
|
|
object N2 : SealedClassWithNestedSubclasses()
|
|
}
|
|
|
|
// --
|
|
|
|
sealed class SealedClassWithNoSubclasses
|
|
|
|
// --
|
|
|
|
fun sealedSubclassNames(c: KClass<*>) = c.sealedSubclasses.map { it.simpleName ?: throw AssertionError("Unnamed class: ${it.java}") }.sorted()
|
|
|
|
fun box(): String {
|
|
assertEquals(listOf("TL1", "TL2"), sealedSubclassNames(SealedClassWithTopLevelSubclasses::class))
|
|
assertEquals(listOf("N1", "N2"), sealedSubclassNames(SealedClassWithNestedSubclasses::class))
|
|
assertEquals(emptyList(), sealedSubclassNames(SealedClassWithNoSubclasses::class))
|
|
|
|
assertEquals(emptyList(), sealedSubclassNames(String::class))
|
|
assertEquals(emptyList(), sealedSubclassNames(Thread::class))
|
|
assertEquals(emptyList(), sealedSubclassNames(FloatArray::class))
|
|
|
|
return "OK"
|
|
}
|