Force wrapping java classes from annotation methods into KClasses

Before this change such wrapping happened only during coercion,
i.e. when a call-site expected a KClass instance.

But when call-site expects Any, for example, no wrapping happened,
and raw j.l.Class instance was left on stack.

The solution is to put wrapping code closer to generation of annotation's
method call itself to guarantee that necessary wrapping will happen.

 #KT-9453 Fixed
This commit is contained in:
Denis Zharkov
2017-03-02 15:19:09 +03:00
parent 415c3d57af
commit 6fb83c2ba3
8 changed files with 157 additions and 14 deletions
@@ -0,0 +1,41 @@
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.KClass
import kotlin.test.assertEquals
annotation class Anno(
val klass: KClass<*>,
val kClasses: Array<KClass<*>>,
vararg val kClassesVararg: KClass<*>
)
@Anno(String::class, arrayOf(Int::class), Double::class)
fun foo() {}
fun Anno.checkReference(expected: Any?, x: Anno.() -> Any?) {
assertEquals(expected, x())
}
fun Anno.checkReferenceArray(expected: Any?, x: Anno.() -> Array<out Any?>) {
assertEquals(expected, x()[0])
}
fun checkBoundReference(expected: Any?, x: () -> Any?) {
assertEquals(expected, x())
}
fun checkBoundReferenceArray(expected: Any?, x: () -> Array<out Any?>) {
assertEquals(expected, x()[0])
}
fun box(): String {
val k = ::foo.annotations.single() as Anno
k.checkReference(String::class, Anno::klass)
k.checkReferenceArray(Int::class, Anno::kClasses)
k.checkReferenceArray(Double::class, Anno::kClassesVararg)
checkBoundReference(String::class, k::klass)
checkBoundReferenceArray(Int::class, k::kClasses)
checkBoundReferenceArray(Double::class, k::kClassesVararg)
return "OK"
}