IR: Handle annotation instantiations in constructor calls

This commit is contained in:
Steven Schäfer
2021-08-19 16:38:33 +02:00
committed by Alexander Udalov
parent fc6c2c9631
commit f05f9882ab
4 changed files with 29 additions and 3 deletions
@@ -454,6 +454,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testMultiplatformInstantiation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt");
}
@Test
@TestMetadata("nestedAnnotationInstances.kt")
public void testNestedAnnotationInstances() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt");
}
}
@Nested
@@ -50,9 +50,9 @@ open class AnnotationImplementationTransformer(val context: BackendContext, val
internal val implementations: MutableMap<IrClass, IrClass> = mutableMapOf()
override fun visitConstructorCall(expression: IrConstructorCall): IrExpression {
val constructedClass = expression.type.classOrNull?.owner ?: return expression
if (!constructedClass.isAnnotationClass) return expression
if (constructedClass.typeParameters.isNotEmpty()) return expression // Not supported yet
val constructedClass = expression.type.classOrNull?.owner ?: return super.visitConstructorCall(expression)
if (!constructedClass.isAnnotationClass) return super.visitConstructorCall(expression)
if (constructedClass.typeParameters.isNotEmpty()) return super.visitConstructorCall(expression) // Not supported yet
val implClass = implementations.getOrPut(constructedClass) { createAnnotationImplementation(constructedClass) }
val ctor = implClass.constructors.single()
@@ -0,0 +1,14 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// !LANGUAGE: +InstantiationOfAnnotationClasses
annotation class NestedAnnotation(val value: String)
annotation class OuterAnnotation(val nested: NestedAnnotation)
class Outer(val nested: NestedAnnotation, val outer: OuterAnnotation)
fun box(): String {
val anno = Outer(NestedAnnotation("O"), OuterAnnotation(NestedAnnotation("K")))
return anno.nested.value + anno.outer.nested.value
}
@@ -454,6 +454,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testMultiplatformInstantiation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt");
}
@Test
@TestMetadata("nestedAnnotationInstances.kt")
public void testNestedAnnotationInstances() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt");
}
}
@Nested