diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt index 32d5edd2b4d..b1d685da04e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.kt @@ -78,6 +78,7 @@ class ScriptCodegen private constructor( scriptDescriptor, scriptContext.earlierScripts ) + val asmMethod = jvmSignature.asmMethod if (state.replSpecific.shouldGenerateScriptResultValue) { val resultFieldInfo = scriptContext.resultFieldInfo @@ -93,6 +94,8 @@ class ScriptCodegen private constructor( OtherOrigin(scriptDeclaration, scriptDescriptor.unsubstitutedPrimaryConstructor), ACC_PUBLIC, jvmSignature.asmMethod.name, jvmSignature.asmMethod.descriptor, null, null) + FunctionCodegen.generateMethodAnnotations(scriptDescriptor.unsubstitutedPrimaryConstructor, asmMethod, mv, this, typeMapper) + if (state.classBuilderMode.generateBodies) { mv.visitCode() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt index c1fe183147d..886ce605ccc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt @@ -33,6 +33,7 @@ class CustomScriptCodegenTest : CodegenTestCase() { val res = generateScriptClass() assertNull(res.safeGetAnnotation(KotlinScript::class)) assertNotNull(res.safeGetAnnotation(MyScriptClassAnnotation::class)) + assertNotNull(res.getConstructor().safeGetAnnotation(MyScriptConstructorAnnotation::class)) } private fun generateScriptClass(): Class<*> = generateClass("ScriptTest") @@ -79,14 +80,21 @@ class CustomScriptCodegenTest : CodegenTestCase() { private fun Class<*>.safeGetAnnotation(ann: KClass): Annotation? = getAnnotation(classLoader.loadClass(ann.qualifiedName) as Class) +private fun java.lang.reflect.Constructor<*>.safeGetAnnotation(ann: KClass): Annotation? = + getAnnotation(this.declaringClass.classLoader.loadClass(ann.qualifiedName) as Class) + @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) annotation class MyScriptClassAnnotation +@Target(AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.RUNTIME) +annotation class MyScriptConstructorAnnotation + @Suppress("unused") @KotlinScript @MyScriptClassAnnotation() -abstract class TestScriptWithAnnotatedBaseClass +abstract class TestScriptWithAnnotatedBaseClass @MyScriptConstructorAnnotation constructor() object TestScriptWithMethodAnnotationsConfiguration : ArrayList, Any?>>( listOf(