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
@@ -20,12 +20,6 @@ public @interface C {
|
||||
String v2();
|
||||
}
|
||||
|
||||
// FILE: D.java
|
||||
|
||||
public @interface D {
|
||||
String value() default "hello";
|
||||
}
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
fun box(): String {
|
||||
@@ -34,10 +28,5 @@ fun box(): String {
|
||||
assert(b.value == "OK")
|
||||
val c = C(v2 = "v2", v1 = intArrayOf(1))
|
||||
assert(c.v2 == "v2")
|
||||
// TODO(KT-47702): Looks like we have to force users either to pass default java parameters explicitly
|
||||
// or hack LazyJavaClassDescriptor/JavaPropertyDescriptor to load annotation param default value,
|
||||
// because it is not stored currently anywhere.
|
||||
// val d = D()
|
||||
val d = D("OK").value
|
||||
return d
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user