diff --git a/compiler/fir/fir-serialization/build.gradle.kts b/compiler/fir/fir-serialization/build.gradle.kts index 6d776887674..94bbcfb81dc 100644 --- a/compiler/fir/fir-serialization/build.gradle.kts +++ b/compiler/fir/fir-serialization/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { api(project(":compiler:fir:cones")) api(project(":compiler:fir:tree")) + api(project(":compiler:fir:java")) api(project(":compiler:fir:providers")) api(project(":compiler:fir:semantics")) api(project(":compiler:fir:resolve")) diff --git a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/constant/FirToConstantValueTransformer.kt b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/constant/FirToConstantValueTransformer.kt index 8ced6285bec..6eb30485acc 100644 --- a/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/constant/FirToConstantValueTransformer.kt +++ b/compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/constant/FirToConstantValueTransformer.kt @@ -9,9 +9,11 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirEnumEntry import org.jetbrains.kotlin.fir.declarations.utils.isConst +import org.jetbrains.kotlin.fir.declarations.utils.isFinal import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationArgumentMapping import org.jetbrains.kotlin.fir.expressions.builder.buildAnnotationCall +import org.jetbrains.kotlin.fir.java.declarations.FirJavaField import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCallTransformer @@ -109,6 +111,7 @@ private abstract class FirToConstantValueTransformer( data: FirSession ): ConstantValue<*>? { val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return null + val fir = symbol.fir return when { symbol.fir is FirEnumEntry -> { @@ -120,6 +123,14 @@ private abstract class FirToConstantValueTransformer( if (symbol.fir.isConst) symbol.fir.initializer?.accept(this, data) else null } + fir is FirJavaField -> { + if (fir.isFinal) { + fir.initializer?.accept(this, data) + } else { + null + } + } + symbol is FirConstructorSymbol -> { val constructorCall = qualifiedAccessExpression as FirFunctionCall val constructedClassSymbol = symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data) ?: return null @@ -232,12 +243,15 @@ internal object FirToConstantValueChecker : FirDefaultVisitor symbol.fir.returnTypeRef.coneTypeSafe()?.classId != null symbol is FirPropertySymbol -> symbol.fir.isConst + fir is FirJavaField -> symbol.fir.isFinal + symbol is FirConstructorSymbol -> { symbol.containingClassLookupTag()?.toFirRegularClassSymbol(data)?.classKind == ClassKind.ANNOTATION_CLASS } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index acf9c1c14f5..d224b47b9b4 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -227,6 +227,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt"); } + @Test + @TestMetadata("javaConstAnnotationArguments.kt") + public void testJavaConstAnnotationArguments() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt"); + } + @Test @TestMetadata("javaNegativePropertyAsAnnotationParameter.kt") public void testJavaNegativePropertyAsAnnotationParameter() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index eb1aef458c2..0822877c786 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -227,6 +227,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt"); } + @Test + @TestMetadata("javaConstAnnotationArguments.kt") + public void testJavaConstAnnotationArguments() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt"); + } + @Test @TestMetadata("javaNegativePropertyAsAnnotationParameter.kt") public void testJavaNegativePropertyAsAnnotationParameter() throws Exception { diff --git a/compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt b/compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt new file mode 100644 index 00000000000..fb881d8a955 --- /dev/null +++ b/compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL +// ISSUE: KT-57879 +// TARGET_BACKEND: JVM_IR + +// FILE: CoreBundle.java + +public class CoreBundle { + public static final String BUNDLE = "OK"; +} + +// FILE: main.kt + +@Target(AnnotationTarget.TYPE) +annotation class AnnKlass(val argument: String) + +fun message(key: @AnnKlass(CoreBundle.BUNDLE) String) = key + +fun box() = message("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 c595339014c..9088c43162c 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 @@ -227,6 +227,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt"); } + @Test + @TestMetadata("javaConstAnnotationArguments.kt") + public void testJavaConstAnnotationArguments() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt"); + } + @Test @TestMetadata("javaNegativePropertyAsAnnotationParameter.kt") public void testJavaNegativePropertyAsAnnotationParameter() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 5caf789d3c0..2a6adc245e3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -227,6 +227,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/annotations/javaAnnotationWithSingleArrayArgument.kt"); } + @Test + @TestMetadata("javaConstAnnotationArguments.kt") + public void testJavaConstAnnotationArguments() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaConstAnnotationArguments.kt"); + } + @Test @TestMetadata("javaNegativePropertyAsAnnotationParameter.kt") public void testJavaNegativePropertyAsAnnotationParameter() throws Exception {