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,42 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM_IR
// IGNORE_DEXING
// WITH_RUNTIME
// !LANGUAGE: +InstantiationOfAnnotationClasses
// MODULE: lib
// FILE: lib.kt
package a
annotation class A(val i: Int)
inline fun foo(i: Int): A = A(i)
inline fun bar(f: () -> Int): A = A(f())
// MODULE: app(lib)
// FILE: app.kt
package test
import a.*
class C {
fun one(): A = foo(1)
fun two(): A = bar { 2 }
}
fun box(): String {
val one = C().one()
val two = C().two()
assert(one.i == 1)
assert(two.i == 2)
// Just like SAM wrappers, annotation implementation classes should be copied from inline functions
// into current module to avoid compatibility problems when inline fun implementation in origin module
// has changed (e.g. do not instantiate annotation anymore)
assert(one.javaClass.getEnclosingClass().getName() == "test.C")
assert(two.javaClass.getEnclosingClass().getName() == "test.C")
return "OK"
}