diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index e3775684f08..24d698c659a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -357,19 +357,19 @@ class Fir2IrVisitor( endOffset, varargArgumentsExpression.typeRef.toIrType(), varargArgumentsExpression.varargElementType.toIrType(), - varargArgumentsExpression.arguments.map { it.convertToIrVarargElement() } + varargArgumentsExpression.arguments.map { it.convertToIrVarargElement(annotationMode = false) } ) } } - private fun FirExpression.convertToIrVarargElement(): IrVarargElement = + private fun FirExpression.convertToIrVarargElement(annotationMode: Boolean): IrVarargElement = if (this is FirSpreadArgumentExpression || this is FirNamedArgumentExpression && this.isSpread) { IrSpreadElementImpl( source?.startOffset ?: UNDEFINED_OFFSET, source?.endOffset ?: UNDEFINED_OFFSET, - convertToIrExpression(this) + convertToIrExpression(this, annotationMode) ) - } else convertToIrExpression(this) + } else convertToIrExpression(this, annotationMode) private fun convertToIrCall(functionCall: FirFunctionCall, annotationMode: Boolean): IrExpression { val explicitReceiverExpression = convertToIrReceiverExpression( @@ -535,8 +535,12 @@ class Fir2IrVisitor( } else -> { val unwrappedExpression = expression.unwrapArgument() - if (annotationMode && unwrappedExpression is FirFunctionCall) { - convertToIrCall(unwrappedExpression, annotationMode) + if (annotationMode) { + when (unwrappedExpression) { + is FirFunctionCall -> convertToIrCall(unwrappedExpression, annotationMode) + is FirArrayOfCall -> convertToArrayOfCall(unwrappedExpression, annotationMode) + else -> expression.accept(this, null) as IrExpression + } } else { expression.accept(this, null) as IrExpression } @@ -1113,7 +1117,7 @@ class Fir2IrVisitor( classifierStorage.getIrClassSymbol(it) } - override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Any?): IrElement { + private fun convertToArrayOfCall(arrayOfCall: FirArrayOfCall, annotationMode: Boolean): IrVararg { return arrayOfCall.convertWithOffsets { startOffset, endOffset -> lateinit var elementType: IrType lateinit var arrayType: IrType @@ -1132,11 +1136,15 @@ class Fir2IrVisitor( startOffset, endOffset, type = arrayType, varargElementType = elementType, - elements = arrayOfCall.arguments.map { it.convertToIrVarargElement() } + elements = arrayOfCall.arguments.map { it.convertToIrVarargElement(annotationMode) } ) } } + override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Any?): IrElement { + return convertToArrayOfCall(arrayOfCall, annotationMode = false) + } + override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: Any?): IrElement { return augmentedArraySetCall.convertWithOffsets { startOffset, endOffset -> IrErrorCallExpressionImpl( diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 940c4d4b10f..2eefc2aa662 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -16839,6 +16839,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt"); } + @Test + @TestMetadata("complexAnnotations.kt") + public void testComplexAnnotations() throws Exception { + runTest("compiler/testData/codegen/box/fir/complexAnnotations.kt"); + } + @Test @TestMetadata("ConstValAccess.kt") public void testConstValAccess() throws Exception { diff --git a/compiler/testData/codegen/box/fir/complexAnnotations.kt b/compiler/testData/codegen/box/fir/complexAnnotations.kt new file mode 100644 index 00000000000..0831cde6c48 --- /dev/null +++ b/compiler/testData/codegen/box/fir/complexAnnotations.kt @@ -0,0 +1,59 @@ +// TARGET_BACKEND: JVM_IR + +// MODULE: m1 +// FILE: State.java +public @interface State { + String name(); + + Storage[] storages() default {}; + + boolean reloadable() default true; + + boolean defaultStateAsResource() default false; + + boolean reportStatistic() default false; +} + +// FILE: Storage.java +public @interface Storage { + String file() default ""; + + String value() default ""; + + boolean deprecated() default false; + + RoamingType roamingType() default RoamingType.DEFAULT; +} + +// FILE: RoamingType.java +public enum RoamingType { + DISABLED, + PER_OS, + DEFAULT, +} + +// FILE: StoragePathMacros.java +public class StoragePathMacros { + public static final String NON_ROAMABLE_FILE = "NON_ROAMABLE_FILE"; +} + +// MODULE: m2(m1) +// FILE: test.kt + +@State(name = "RecentDirectoryProjectsManager", + storages = [Storage(value = "recentProjectDirectories.xml", roamingType = RoamingType.DISABLED, deprecated = true)], + reportStatistic = false) +class Some + +@State(name = "RecentProjectsManager", storages = [Storage(value = "recentProjects.xml", roamingType = RoamingType.DISABLED)]) +class Other + +@State(name = "A", storages = [(Storage(value = StoragePathMacros.NON_ROAMABLE_FILE))]) +class Another + +fun box(): String { + Some() + Other() + Another() + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 55f1887075c..ae2d6a721fe 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -16839,6 +16839,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt"); } + @Test + @TestMetadata("complexAnnotations.kt") + public void testComplexAnnotations() throws Exception { + runTest("compiler/testData/codegen/box/fir/complexAnnotations.kt"); + } + @Test @TestMetadata("ConstValAccess.kt") public void testConstValAccess() throws Exception {