Files
kotlin-fork/compiler/testData/codegen/box/reflection/parameters/functionParameterNameAndIndex.kt
T
Vladimir Sukharev 05e22e56d3 [K/N] Mark rest of reflection related tests as jvm-only
^KT-59057

Merge-request: KT-MR-10570
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-16 11:50:03 +00:00

37 lines
847 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.reflect.full.*
import kotlin.test.assertEquals
fun foo(bar: String): Int = bar.length
class A(val c: String) {
fun foz(baz: Int) {}
fun Double.mext(mez: Long) {}
}
fun Int.qux(zux: String) {}
fun checkParameters(f: KFunction<*>, names: List<String?>) {
val params = f.parameters
assertEquals(names, params.map { it.name })
assertEquals(params.indices.toList(), params.map { it.index })
}
fun box(): String {
checkParameters(::box, listOf())
checkParameters(::foo, listOf("bar"))
checkParameters(A::foz, listOf(null, "baz"))
checkParameters(Int::qux, listOf(null, "zux"))
checkParameters(A::class.functions.single { it.name == "mext" }, listOf(null, null, "mez"))
checkParameters(::A, listOf("c"))
return "OK"
}