IR: Handle annotation instantiations in constructor calls
This commit is contained in:
committed by
Alexander Udalov
parent
fc6c2c9631
commit
f05f9882ab
+6
@@ -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
|
||||
|
||||
+3
-3
@@ -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()
|
||||
|
||||
+14
@@ -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
|
||||
}
|
||||
+6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user