FIR: recursive transform annotation if it has annotation as argument

#KT-42344 Fixed
This commit is contained in:
Mikhail Glukhikh
2020-09-30 12:55:49 +03:00
parent 2fd752f8f6
commit 582f8fe287
6 changed files with 219 additions and 6 deletions
@@ -61,12 +61,16 @@ class IrConstTransformer(irBuiltIns: IrBuiltIns) : IrElementTransformerVoid() {
private fun transformAnnotations(annotationContainer: IrAnnotationContainer) {
annotationContainer.annotations.forEach { annotation ->
for (i in 0 until annotation.valueArgumentsCount) {
val arg = annotation.getValueArgument(i) ?: continue
when (arg) {
is IrVararg -> annotation.putValueArgument(i, arg.transformVarArg())
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
}
transformAnnotation(annotation)
}
}
private fun transformAnnotation(annotation: IrConstructorCall) {
for (i in 0 until annotation.valueArgumentsCount) {
val arg = annotation.getValueArgument(i) ?: continue
when (arg) {
is IrVararg -> annotation.putValueArgument(i, arg.transformVarArg())
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
}
}
}
@@ -92,6 +96,8 @@ class IrConstTransformer(irBuiltIns: IrBuiltIns) : IrElementTransformerVoid() {
if (this.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
val const = interpreter.interpret(this).replaceIfError(this)
return const.convertToConstIfPossible(expectedType)
} else if (this is IrConstructorCall) {
transformAnnotation(this)
}
return this
}
@@ -1717,6 +1717,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/firProblems"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("AnnotationInAnnotation.kt")
public void testAnnotationInAnnotation() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.kt");
}
@TestMetadata("candidateSymbol.kt")
public void testCandidateSymbol() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/candidateSymbol.kt");