diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index 3ad72267ec3..c28656e96e8 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.backend.generators +import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.declarations.* @@ -103,8 +104,9 @@ internal class ClassMemberGenerator( irFunction.putParametersInScope(firFunction) } } + val annotationMode = containingClass?.classKind == ClassKind.ANNOTATION_CLASS && irFunction is IrConstructor for ((valueParameter, firValueParameter) in valueParameters.zip(firFunction.valueParameters)) { - valueParameter.setDefaultValue(firValueParameter) + valueParameter.setDefaultValue(firValueParameter, annotationMode) annotationGenerator.generate(valueParameter, firValueParameter, irFunction is IrConstructor) } annotationGenerator.generate(irFunction, firFunction) @@ -345,10 +347,10 @@ internal class ClassMemberGenerator( } } - private fun IrValueParameter.setDefaultValue(firValueParameter: FirValueParameter) { + private fun IrValueParameter.setDefaultValue(firValueParameter: FirValueParameter, annotationMode: Boolean) { val firDefaultValue = firValueParameter.defaultValue if (firDefaultValue != null) { - this.defaultValue = factory.createExpressionBody(visitor.convertToIrExpression(firDefaultValue)) + this.defaultValue = factory.createExpressionBody(visitor.convertToIrExpression(firDefaultValue, annotationMode)) } } } 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 ab2beb4c133..d3785da1f93 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 @@ -89,6 +89,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinPropertyFromInterfaceCompanion.kt"); } + @Test + @TestMetadata("annotationWithVarargAsDefaultValue.kt") + public void testAnnotationWithVarargAsDefaultValue() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationWithVarargAsDefaultValue.kt"); + } + @Test @TestMetadata("annotationsOnDefault.kt") public void testAnnotationsOnDefault() throws Exception { diff --git a/compiler/testData/codegen/box/annotations/annotationWithVarargAsDefaultValue.kt b/compiler/testData/codegen/box/annotations/annotationWithVarargAsDefaultValue.kt new file mode 100644 index 00000000000..be87f58d71e --- /dev/null +++ b/compiler/testData/codegen/box/annotations/annotationWithVarargAsDefaultValue.kt @@ -0,0 +1,13 @@ +// TARGET_BACKEND: JVM_IR + +annotation class MyReplaceWith(val x: String, vararg val y: String) + +annotation class MyDeprecated( + val replaceWith: MyReplaceWith = MyReplaceWith(""), +) + +fun getInt(x: String, vararg y: String): Int = 1 + +fun test(x: Int = getInt("")) {} + +fun box() = "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 87f15c13aa1..d38390f8cd0 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 @@ -89,6 +89,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinPropertyFromInterfaceCompanion.kt"); } + @Test + @TestMetadata("annotationWithVarargAsDefaultValue.kt") + public void testAnnotationWithVarargAsDefaultValue() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationWithVarargAsDefaultValue.kt"); + } + @Test @TestMetadata("annotationsOnDefault.kt") public void testAnnotationsOnDefault() throws Exception {