KT-13440 Bound callable references in reflection
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_REFLECT
|
||||
import kotlin.reflect.KParameter
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Outer(val s1: String) {
|
||||
inner class Inner(val s2: String, val s3: String = "K") {
|
||||
val result = s1 + s2 + s3
|
||||
}
|
||||
}
|
||||
|
||||
fun KParameter.check(name: String) {
|
||||
assertEquals(name, this.name!!)
|
||||
assertEquals(KParameter.Kind.VALUE, this.kind)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ctor = Outer("O")::Inner
|
||||
val ctorPararms = ctor.parameters
|
||||
|
||||
ctorPararms[0].check("s2")
|
||||
ctorPararms[1].check("s3")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object Host {
|
||||
fun foo(i: Int, s: String) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val fooParams = Host::foo.parameters
|
||||
|
||||
assertEquals(2, fooParams.size)
|
||||
|
||||
assertEquals("i", fooParams[0].name)
|
||||
assertEquals(Int::class.java, fooParams[0].type.javaType)
|
||||
|
||||
assertEquals("s", fooParams[1].name)
|
||||
assertEquals(String::class.java, fooParams[1].type.javaType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.*
|
||||
|
||||
class C {
|
||||
fun foo() {}
|
||||
var bar = "OK"
|
||||
}
|
||||
|
||||
fun C.extFun(i: Int) {}
|
||||
|
||||
fun KParameter.check(name: String) {
|
||||
assertEquals(name, this.name!!)
|
||||
assertEquals(KParameter.Kind.VALUE, this.kind)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val cFoo = C()::foo
|
||||
val cBar = C()::bar
|
||||
val cExtFun = C()::extFun
|
||||
|
||||
assertEquals(0, cFoo.parameters.size)
|
||||
assertEquals(0, cBar.getter.parameters.size)
|
||||
assertEquals(1, cBar.setter.parameters.size)
|
||||
|
||||
assertEquals(1, cExtFun.parameters.size)
|
||||
cExtFun.parameters[0].check("i")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user