diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 63535a038f3..1961a298a42 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -156,18 +156,22 @@ class FunctionCodegen( } val isVararg = valueParameters.lastOrNull()?.varargElementType != null && !isBridge() - val modalityFlag = when ((this as? IrSimpleFunction)?.modality) { - Modality.FINAL -> when { - origin == JvmLoweredDeclarationOrigin.CLASS_STATIC_INITIALIZER -> 0 - origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> 0 - parentAsClass.isInterface && body != null -> 0 - parentAsClass.isAnnotationClass -> if (isStatic) 0 else Opcodes.ACC_ABSTRACT - else -> Opcodes.ACC_FINAL + val modalityFlag = + if (parentAsClass.isAnnotationClass) { + if (isStatic) 0 else Opcodes.ACC_ABSTRACT + } else { + when ((this as? IrSimpleFunction)?.modality) { + Modality.FINAL -> when { + origin == JvmLoweredDeclarationOrigin.CLASS_STATIC_INITIALIZER -> 0 + origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> 0 + parentAsClass.isInterface && body != null -> 0 + else -> Opcodes.ACC_FINAL + } + Modality.ABSTRACT -> Opcodes.ACC_ABSTRACT + // TODO transform interface modality on lowering to DefaultImpls + else -> if (parentAsClass.isJvmInterface && body == null) Opcodes.ACC_ABSTRACT else 0 + } } - Modality.ABSTRACT -> Opcodes.ACC_ABSTRACT - // TODO transform interface modality on lowering to DefaultImpls - else -> if (parentAsClass.isJvmInterface && body == null) Opcodes.ACC_ABSTRACT else 0 - } val isSynthetic = origin.isSynthetic || hasAnnotation(JVM_SYNTHETIC_ANNOTATION_FQ_NAME) || isReifiable() || diff --git a/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/BytecodeListingTestForAllOpenGenerated.java b/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/BytecodeListingTestForAllOpenGenerated.java index 9fb66f3ddc8..26aa87888e6 100644 --- a/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/BytecodeListingTestForAllOpenGenerated.java +++ b/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/BytecodeListingTestForAllOpenGenerated.java @@ -39,6 +39,11 @@ public class BytecodeListingTestForAllOpenGenerated extends AbstractBytecodeList runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/alreadyOpen.kt"); } + @TestMetadata("annotationMembers.kt") + public void testAnnotationMembers() throws Exception { + runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.kt"); + } + @TestMetadata("anonymousObject.kt") public void testAnonymousObject() throws Exception { runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/anonymousObject.kt"); diff --git a/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/IrBytecodeListingTestForAllOpenGenerated.java b/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/IrBytecodeListingTestForAllOpenGenerated.java index 8de3846a346..cdac8532697 100644 --- a/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/IrBytecodeListingTestForAllOpenGenerated.java +++ b/plugins/allopen/allopen-cli/test/org/jetbrains/kotlin/allopen/IrBytecodeListingTestForAllOpenGenerated.java @@ -39,6 +39,11 @@ public class IrBytecodeListingTestForAllOpenGenerated extends AbstractIrBytecode runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/alreadyOpen.kt"); } + @TestMetadata("annotationMembers.kt") + public void testAnnotationMembers() throws Exception { + runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.kt"); + } + @TestMetadata("anonymousObject.kt") public void testAnonymousObject() throws Exception { runTest("plugins/allopen/allopen-cli/testData/bytecodeListing/anonymousObject.kt"); diff --git a/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.kt b/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.kt new file mode 100644 index 00000000000..a63f037b43f --- /dev/null +++ b/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.kt @@ -0,0 +1,18 @@ +// WITH_RUNTIME + +annotation class AllOpen + +annotation class Plain(val name: String, val index: Int) { + companion object { + @JvmStatic val staticProperty = 42 + @JvmStatic fun staticFun() {} + } +} + +@AllOpen +annotation class MyComponent(val name: String, val index: Int) { + companion object { + @JvmStatic val staticProperty = 42 + @JvmStatic fun staticFun() {} + } +} diff --git a/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.txt b/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.txt new file mode 100644 index 00000000000..672efa422f2 --- /dev/null +++ b/plugins/allopen/allopen-cli/testData/bytecodeListing/annotationMembers.txt @@ -0,0 +1,58 @@ +@java.lang.annotation.Retention +@kotlin.Metadata +public annotation class AllOpen { + // source: 'annotationMembers.kt' +} + +@kotlin.Metadata +public final class MyComponent$Companion { + // source: 'annotationMembers.kt' + synthetic final static field $$INSTANCE: MyComponent$Companion + private final static field staticProperty: int + static method (): void + private method (): void + public synthetic deprecated static @kotlin.jvm.JvmStatic method getStaticProperty$annotations(): void + public final method getStaticProperty(): int + public final @kotlin.jvm.JvmStatic method staticFun(): void + public final inner class MyComponent$Companion +} + +@AllOpen +@java.lang.annotation.Retention +@kotlin.Metadata +public annotation class MyComponent { + // source: 'annotationMembers.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: MyComponent$Companion + static method (): void + public static method getStaticProperty(): int + public abstract method index(): int + public abstract method name(): java.lang.String + public static @kotlin.jvm.JvmStatic method staticFun(): void + public final inner class MyComponent$Companion +} + +@kotlin.Metadata +public final class Plain$Companion { + // source: 'annotationMembers.kt' + synthetic final static field $$INSTANCE: Plain$Companion + private final static field staticProperty: int + static method (): void + private method (): void + public synthetic deprecated static @kotlin.jvm.JvmStatic method getStaticProperty$annotations(): void + public final method getStaticProperty(): int + public final @kotlin.jvm.JvmStatic method staticFun(): void + public final inner class Plain$Companion +} + +@java.lang.annotation.Retention +@kotlin.Metadata +public annotation class Plain { + // source: 'annotationMembers.kt' + public final static @org.jetbrains.annotations.NotNull field Companion: Plain$Companion + static method (): void + public static method getStaticProperty(): int + public abstract method index(): int + public abstract method name(): java.lang.String + public static @kotlin.jvm.JvmStatic method staticFun(): void + public final inner class Plain$Companion +}