[FIR2IR] Properly generate arguments for annotation constructors calls in default values of annotation constructors
This commit is contained in:
committed by
teamcity
parent
18fc2802e5
commit
4022918ea2
+5
-3
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+13
@@ -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"
|
||||
+6
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user