diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt index d8d76b5f51c..80bf6933ad3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt @@ -251,5 +251,6 @@ private class MakeCallsStatic( private fun isJvmStaticFunction(declaration: IrDeclaration): Boolean = declaration is IrSimpleFunction && (declaration.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) || - declaration.correspondingPropertySymbol?.owner?.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) == true) + declaration.correspondingPropertySymbol?.owner?.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) == true) && + declaration.origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS diff --git a/compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt b/compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt new file mode 100644 index 00000000000..f8b4020b7bc --- /dev/null +++ b/compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt @@ -0,0 +1,61 @@ +// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK +// JVM_TARGET: 1.8 + +package test + +import java.lang.reflect.Modifier +import kotlin.test.* + +class WithCompanionJvmStatic { + + companion object { + @JvmStatic + val property: Int + get() = 42 + } +} + +interface InterfaceWithCompanionJvmStatic { + + fun defaultImplsTrigger() = 123 + + companion object { + @JvmStatic + val property: Int + get() = 42 + } +} + +fun check(clazz: Class<*>, expected: Boolean = true) { + for (method in clazz.getDeclaredMethods()) { + if (method.getName() == "getProperty\$annotations") { + if (!expected) { + fail("Synthetic method for annotated property found, but not expected: $method") + } + assertTrue(method.isSynthetic()) + assertTrue(Modifier.isStatic(method.modifiers)) + assertTrue(Modifier.isPublic(method.modifiers)) + val str = method.declaredAnnotations.single().toString() + assertTrue("@kotlin.jvm.JvmStatic\\(\\)".toRegex().matches(str), str) + return + } + } + if (expected) { + fail("Synthetic method for annotated property expected, but not found") + } +} + +fun box(): String { + check(Class.forName("test.WithCompanionJvmStatic"), expected = false) + check(Class.forName("test.WithCompanionJvmStatic\$Companion")) + + check(Class.forName("test.InterfaceWithCompanionJvmStatic"), expected = false) + check(Class.forName("test.InterfaceWithCompanionJvmStatic\$DefaultImpls"), expected = false) + check(Class.forName("test.InterfaceWithCompanionJvmStatic\$Companion")) + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index da6c8b8a884..ed47a838f32 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -186,6 +186,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForJvmStaticProperty.kt") + public void testSyntheticMethodForJvmStaticProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt"); + } + @TestMetadata("syntheticMethodForProperty.kt") public void testSyntheticMethodForProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 790508895c4..109af5b25ed 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -191,6 +191,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForJvmStaticProperty.kt") + public void testSyntheticMethodForJvmStaticProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt"); + } + @TestMetadata("syntheticMethodForProperty.kt") public void testSyntheticMethodForProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e41e4db6985..11e0176de57 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -186,6 +186,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForJvmStaticProperty.kt") + public void testSyntheticMethodForJvmStaticProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt"); + } + @TestMetadata("syntheticMethodForProperty.kt") public void testSyntheticMethodForProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 174749c3a51..30b5e04878d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -186,6 +186,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForJvmStaticProperty.kt") + public void testSyntheticMethodForJvmStaticProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt"); + } + @TestMetadata("syntheticMethodForProperty.kt") public void testSyntheticMethodForProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");