Support instantiation of Java annotations with defaults
For annotations defined in Java, IrProperties do not contain initializers in backing fields, as annotation properties are represented as Java methods. Therefore, it is not possible to use initializer values as default values for constructor parameters. However, K2 stores default values in annotation's constructor parameters, so it is possible to fix this issue if they're properly transfered to the IR and inspected in JvmAnnotationImplementationTransformer #KT-47702 Fixed #KT-47702 tag fixed-in-k2
This commit is contained in:
committed by
Space Team
parent
cc2bc5e8b1
commit
7f795f212f
+31
@@ -0,0 +1,31 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_K1: JVM_IR
|
||||
// IGNORE_DEXING
|
||||
// WITH_STDLIB
|
||||
// !LANGUAGE: +InstantiationOfAnnotationClasses
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: LibAnnotation.java
|
||||
|
||||
package a;
|
||||
|
||||
public @interface LibAnnotation {
|
||||
long longValue() default 4;
|
||||
String stringValue() default "OK";
|
||||
Class<?> classValue() default String.class;
|
||||
float[] floatArrayValue() default { 9.0f, 10.0f };
|
||||
}
|
||||
|
||||
// MODULE: app(lib)
|
||||
// FILE: app.kt
|
||||
|
||||
package test
|
||||
|
||||
import a.*
|
||||
|
||||
fun box(): String {
|
||||
val l = LibAnnotation()
|
||||
if (l.toString() != "@a.LibAnnotation(longValue=4, stringValue=OK, classValue=class java.lang.String, floatArrayValue=[9.0, 10.0])")
|
||||
return l.toString()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user