Instantiation of annotations for JVM IR with the corresponding feature flag

Seperate checker for platforms that do not support this language feature yet

Synthetic implementations of annotations are generated on-demand with proper 
equals, hashCode, and annotationType methods

#KT-47699 Fixed
This commit is contained in:
Leonid Startsev
2021-07-21 10:23:51 +00:00
committed by Space
parent 4bc521249b
commit ce0a3a57df
59 changed files with 1589 additions and 64 deletions
@@ -0,0 +1,53 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// !LANGUAGE: +InstantiationOfAnnotationClasses
// FILE: a.kt
package test
annotation class A1
annotation class A2
fun interface I {
fun run(): A1
}
// FILE: test.kt
package test
class E {
fun insideClass(): A1 = A1()
fun insideLammbda(): A1 = run { A1() }
fun insideSAM(): I = I { A1() }
}
class G {
// test that we can reuse instance in different classes from same file
fun insideClassAgain(): A1 = A1()
}
fun outsideClass(): A2 = A2()
fun test(instance: Any, parent: String, fqa: String) {
val clz = instance.javaClass
assert(clz.getName().startsWith(parent))
assert(clz.getName().contains(fqa))
assert(clz.getEnclosingMethod() == null)
assert(clz.getEnclosingClass().getName() == parent)
// SAM treated as anonymous because of Origin or something else, see ClassCodegen#IrClass.isAnonymousInnerClass
// assert(clz.getDeclaringClass() == null)
}
fun box(): String {
test(E().insideClass(), "test.E", "test_A1")
test(E().insideLammbda(), "test.E", "test_A1")
test(E().insideSAM().run(), "test.E", "test_A1")
test(G().insideClassAgain(), "test.E", "test_A1")
test(outsideClass(), "test.TestKt", "test_A2")
return "OK"
}