From a238d6a8903aefe830441043879d9e580f74e987 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 2 Jul 2020 14:28:08 +0300 Subject: [PATCH] JVM_IR: no annotations on parameters of 'property$annotations' methods --- .../backend/jvm/codegen/FunctionCodegen.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 8985624841f..703f3c17c5a 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 @@ -86,9 +86,7 @@ class FunctionCodegen( ) } }.genAnnotations(irFunction, signature.asmMethod.returnType, irFunction.returnType) - // Not generating parameter annotations for default stubs fixes KT-7892, though - // this certainly looks like a workaround for a javac bug. - if (irFunction !is IrConstructor || !irFunction.parentAsClass.shouldNotGenerateConstructorParameterAnnotations()) { + if (shouldGenerateAnnotationsOnValueParameters()) { generateParameterAnnotations(irFunction, methodVisitor, signature, classCodegen, context, skipNullabilityAnnotations) } } @@ -120,6 +118,18 @@ class FunctionCodegen( return SMAPAndMethodNode(methodNode, smap) } + private fun shouldGenerateAnnotationsOnValueParameters(): Boolean = + when { + irFunction.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS -> + false + irFunction is IrConstructor && irFunction.parentAsClass.shouldNotGenerateConstructorParameterAnnotations() -> + // Not generating parameter annotations for default stubs fixes KT-7892, though + // this certainly looks like a workaround for a javac bug. + false + else -> + true + } + // Since the only arguments to anonymous object constructors are captured variables and complex // super constructor arguments, there shouldn't be any annotations on them other than @NonNull, // and those are meaningless on synthetic parameters. (Also, the inliner cannot handle them and