Check expected type of annotation parameter correctly in AnnotationDeserializer
The main idea of this refactoring is to separate two usages of `AnnotationDeserializer.resolveValue`: the one where we load annotation argument values, and the one where we load constant values of properties for JS/Native/Common (`AnnotationAndConstantLoaderImpl.loadPropertyConstant`). In the latter case, `expectedType` is the type of the property and it can be a supertype of the actual value (e.g. see `arrayConst` in compiler/testData/serialization/builtinsSerializer/compileTimeConstants.kt). But in the former case, we need to check that the value conforms to the expected type and disregard it if it's not the case, which is possible if the annotation was recompiled separately. #KT-28927
This commit is contained in:
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Anno(
|
||||
val k1: KClass<out CharSequence>,
|
||||
val k2: KClass<in String>,
|
||||
val ka: Array<KClass<out Number>>
|
||||
)
|
||||
|
||||
fun f(): @Anno(String::class, CharSequence::class, [Double::class, Long::class, Int::class]) Unit {}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(
|
||||
"[@Anno(k1=class java.lang.String, k2=interface java.lang.CharSequence, " +
|
||||
"ka=[class java.lang.Double, class java.lang.Long, class java.lang.Integer])]",
|
||||
::f.returnType.annotations.toString()
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user