Files
kotlin/compiler/testData/codegen/box/reflection/constructors/primaryConstructor.kt
Alexander Udalov c357967c2c JVM IR: generate Kotlin metadata
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
2019-02-19 16:37:47 +01:00

61 lines
1.2 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertNull
import kotlin.test.assertNotNull
import kotlin.reflect.full.*
class OnlyPrimary
class PrimaryWithSecondary(val s: String) {
constructor(x: Int) : this(x.toString())
override fun toString() = s
}
class OnlySecondary {
constructor(s: String)
}
class TwoSecondaries {
constructor(s: String)
constructor(d: Double)
}
enum class En
interface I
object O
class C {
companion object
}
fun box(): String {
val p1 = OnlyPrimary::class.primaryConstructor
assertNotNull(p1)
assert(p1!!.call() is OnlyPrimary)
val p2 = PrimaryWithSecondary::class.primaryConstructor
assertNotNull(p2)
assert(p2!!.call("beer").toString() == "beer")
val p3 = OnlySecondary::class.primaryConstructor
assertNull(p3)
val p4 = TwoSecondaries::class.primaryConstructor
assertNull(p4)
assertNotNull(En::class.primaryConstructor)
assertNull(I::class.primaryConstructor)
assertNull(O::class.primaryConstructor)
assertNull(C.Companion::class.primaryConstructor)
assertNull(object {}::class.primaryConstructor)
return "OK"
}