From 3ae75a5094924fac81d0fdabf89eebc4d5930629 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 18 Jul 2022 16:57:56 +0200 Subject: [PATCH] FIR2IR: generate annotations on fake override parameters #KT-53208 Fixed --- .../fir/backend/Fir2IrDeclarationStorage.kt | 7 +- .../FirBlackBoxCodegenTestGenerated.java | 6 + .../runners/ir/Fir2IrTextTestGenerated.java | 6 + .../ir/LightTreeFir2IrTextTestGenerated.java | 6 + .../findAnnotationOnDefaultMethodParameter.kt | 24 ++++ .../ir/irText/classes/kt43217.fir.ir.txt | 4 + ...otationOnDefaultMethodParameter.fir.ir.txt | 102 +++++++++++++++++ ...otationOnDefaultMethodParameter.fir.kt.txt | 36 ++++++ ...dAnnotationOnDefaultMethodParameter.ir.txt | 108 ++++++++++++++++++ ...tFindAnnotationOnDefaultMethodParameter.kt | 22 ++++ ...dAnnotationOnDefaultMethodParameter.kt.txt | 36 ++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 + .../test/runners/ir/IrTextTestGenerated.java | 6 + .../klib/KlibTextTestCaseGenerated.java | 5 + 14 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt create mode 100644 compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.ir.txt create mode 100644 compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.kt.txt create mode 100644 compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.ir.txt create mode 100644 compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt create mode 100644 compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 7040edd02fa..c5e6a85d44c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -556,12 +556,12 @@ class Fir2IrDeclarationStorage( containerSource = simpleFunction?.containerSource, ).apply { metadata = FirMetadataSource.Function(function) - convertAnnotationsForNonDeclaredMembers(function, origin) enterScope(this) bindAndDeclareParameters( function, irParent, thisReceiverOwner, isStatic = simpleFunction?.isStatic == true ) + convertAnnotationsForNonDeclaredMembers(function, origin) leaveScope(this) } } @@ -1595,6 +1595,11 @@ class Fir2IrDeclarationStorage( || origin == IrDeclarationOrigin.FAKE_OVERRIDE ) { annotationGenerator.generate(this, firAnnotationContainer) + if (this is IrFunction && firAnnotationContainer is FirSimpleFunction) { + valueParameters.zip(firAnnotationContainer.valueParameters).forEach { (irParameter, firParameter) -> + annotationGenerator.generate(irParameter, firParameter, isInConstructor = false) + } + } } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index f7bcbb89ab9..673c645543d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -17817,6 +17817,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/fir/falsePositiveBoundSmartcast.kt"); } + @Test + @TestMetadata("findAnnotationOnDefaultMethodParameter.kt") + public void testFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt"); + } + @Test @TestMetadata("Fir2IrClassifierStorage.kt") public void testFir2IrClassifierStorage() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 60de8481032..1f8deb43934 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2632,6 +2632,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.kt"); } + @Test + @TestMetadata("reflectFindAnnotationOnDefaultMethodParameter.kt") + public void testReflectFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt"); + } + @Test @TestMetadata("reflectGetOnNullableTypeAlias.kt") public void testReflectGetOnNullableTypeAlias() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java index 41bcf2f0490..4f29e0465c3 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/LightTreeFir2IrTextTestGenerated.java @@ -2632,6 +2632,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex runTest("compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.kt"); } + @Test + @TestMetadata("reflectFindAnnotationOnDefaultMethodParameter.kt") + public void testReflectFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt"); + } + @Test @TestMetadata("reflectGetOnNullableTypeAlias.kt") public void testReflectGetOnNullableTypeAlias() throws Exception { diff --git a/compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt b/compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt new file mode 100644 index 00000000000..311bc7d510c --- /dev/null +++ b/compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt @@ -0,0 +1,24 @@ +// TARGET_BACKEND: JVM_IR +// WITH_REFLECT +// FULL_JDK +// SKIP_JDK6 +// IGNORE_BACKEND: ANDROID + +fun box(): String { + val impl = object : I { + } + + val method = impl.javaClass.getMethod("m", String::class.java) + val parameter = method.parameters[0] + + val size = parameter.annotations.size + if (size == 1) return "OK" + return "ERR: $size" +} + +annotation class Ann + +interface I { + fun m(@Ann s: String) { + } +} diff --git a/compiler/testData/ir/irText/classes/kt43217.fir.ir.txt b/compiler/testData/ir/irText/classes/kt43217.fir.ir.txt index 0d40e5a1d2b..46ea8c43d4c 100644 --- a/compiler/testData/ir/irText/classes/kt43217.fir.ir.txt +++ b/compiler/testData/ir/irText/classes/kt43217.fir.ir.txt @@ -37,6 +37,8 @@ FILE fqName: fileName:/kt43217.kt public open fun isEqualTo (value: @[EnhancedNullability] kotlin.Double): @[EnhancedNullability] kotlin.Any [fake_override] declared in .DoubleExpression $this: VALUE_PARAMETER name: type:.ObservableValue.ObservableValue> VALUE_PARAMETER name:value index:0 type:@[EnhancedNullability] kotlin.Double + annotations: + NotNull(value = ) FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .DoubleExpression @@ -99,6 +101,8 @@ FILE fqName: fileName:/kt43217.kt public open fun isEqualTo (value: @[EnhancedNullability] kotlin.Double): @[EnhancedNullability] kotlin.Any [fake_override] declared in .DoubleExpression $this: VALUE_PARAMETER name: type:.ObservableValue.ObservableValue> VALUE_PARAMETER name:value index:0 type:@[EnhancedNullability] kotlin.Double + annotations: + NotNull(value = ) FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .DoubleExpression diff --git a/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.ir.txt b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.ir.txt new file mode 100644 index 00000000000..8024712dd41 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.ir.txt @@ -0,0 +1,102 @@ +FILE fqName: fileName:/reflectFindAnnotationOnDefaultMethodParameter.kt + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:impl type:.box. [val] + BLOCK type=.box. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[.I] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box. + CONSTRUCTOR visibility:private <> () returnType:.box. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.I]' + FUN FAKE_OVERRIDE name:m visibility:public modality:OPEN <> ($this:.I, s:kotlin.String) returnType:kotlin.Unit [fake_override] + overridden: + public open fun m (s: kotlin.String): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.I + VALUE_PARAMETER name:s index:0 type:kotlin.String + annotations: + Ann + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'private constructor () [primary] declared in .box.' type=.box. origin=OBJECT_LITERAL + VAR name:method type:@[FlexibleNullability] java.lang.reflect.Method? [val] + CALL 'public open fun getMethod (p0: @[FlexibleNullability] kotlin.String?, vararg p1: @[FlexibleNullability] java.lang.Class<*>?): @[FlexibleNullability] java.lang.reflect.Method? declared in java.lang.Class' type=@[FlexibleNullability] java.lang.reflect.Method? origin=null + $this: CALL 'public final fun (): java.lang.Class> [inline] declared in kotlin.jvm.JvmClassMappingKt' type=java.lang.Class<.box.> origin=GET_PROPERTY + : .box. + $receiver: GET_VAR 'val impl: .box. [val] declared in .box' type=.box. origin=null + p0: CONST String type=kotlin.String value="m" + p1: VARARG type=@[FlexibleNullability] kotlin.Array?>? varargElementType=@[FlexibleNullability] java.lang.Class<*>? + CALL 'public final fun (): java.lang.Class> declared in kotlin.jvm.JvmClassMappingKt' type=java.lang.Class origin=GET_PROPERTY + : kotlin.String + $receiver: CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:String modality:FINAL visibility:public superTypes:[kotlin.Comparable; kotlin.CharSequence; java.io.Serializable]' type=kotlin.reflect.KClass + VAR name:parameter type:@[FlexibleNullability] java.lang.reflect.Parameter? [val] + CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=@[FlexibleNullability] java.lang.reflect.Parameter? origin=null + $this: CALL 'public open fun getParameters (): @[FlexibleNullability] kotlin.Array? [fake_override] declared in java.lang.reflect.Method' type=@[FlexibleNullability] kotlin.Array? origin=GET_PROPERTY + $this: GET_VAR 'val method: @[FlexibleNullability] java.lang.reflect.Method? [val] declared in .box' type=@[FlexibleNullability] java.lang.reflect.Method? origin=null + index: CONST Int type=kotlin.Int value=0 + VAR name:size type:kotlin.Int [val] + CALL 'public final fun (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY + $this: CALL 'public open fun getAnnotations (): @[FlexibleNullability] kotlin.Array? declared in java.lang.reflect.Parameter' type=@[FlexibleNullability] kotlin.Array? origin=GET_PROPERTY + $this: GET_VAR 'val parameter: @[FlexibleNullability] java.lang.reflect.Parameter? [val] declared in .box' type=@[FlexibleNullability] java.lang.reflect.Parameter? origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val size: kotlin.Int [val] declared in .box' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=1 + then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="ERR: " + GET_VAR 'val size: kotlin.Int [val] declared in .box' type=kotlin.Int origin=null + CLASS ANNOTATION_CLASS name:Ann modality:OPEN visibility:public superTypes:[kotlin.Annotation] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Ann + CONSTRUCTOR visibility:public <> () returnType:.Ann [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Ann modality:OPEN visibility:public superTypes:[kotlin.Annotation]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I + FUN name:m visibility:public modality:OPEN <> ($this:.I, s:kotlin.String) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.I + VALUE_PARAMETER name:s index:0 type:kotlin.String + annotations: + Ann + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.kt.txt b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.kt.txt new file mode 100644 index 00000000000..c76d0053f64 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.fir.kt.txt @@ -0,0 +1,36 @@ +fun box(): String { + val impl: = { // BLOCK + local class : I { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + () + } + val method: @FlexibleNullability Method? = impl.<>().getMethod(p0 = "m", p1 = [String::class.()]) + val parameter: @FlexibleNullability Parameter? = method.getParameters().get(index = 0) + val size: Int = parameter.getAnnotations().() + when { + EQEQ(arg0 = size, arg1 = 1) -> return "OK" + } + return "ERR: " + size +} + +open annotation class Ann : Annotation { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +interface I { + fun m(@Ann s: String) { + } + +} diff --git a/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.ir.txt b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.ir.txt new file mode 100644 index 00000000000..a28bb6aa0bc --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.ir.txt @@ -0,0 +1,108 @@ +FILE fqName: fileName:/reflectFindAnnotationOnDefaultMethodParameter.kt + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + VAR name:impl type:.box. [val] + BLOCK type=.box. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[.I] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.box. + CONSTRUCTOR visibility:public <> () returnType:.box. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.I]' + FUN FAKE_OVERRIDE name:m visibility:public modality:OPEN <> ($this:.I, s:kotlin.String) returnType:kotlin.Unit [fake_override] + overridden: + public open fun m (s: kotlin.String): kotlin.Unit declared in .I + $this: VALUE_PARAMETER name: type:.I + VALUE_PARAMETER name:s index:0 type:kotlin.String + annotations: + Ann + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .I + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .box.' type=.box. origin=OBJECT_LITERAL + VAR name:method type:@[FlexibleNullability] java.lang.reflect.Method? [val] + CALL 'public open fun getMethod (p0: @[FlexibleNullability] kotlin.String?, vararg p1: @[FlexibleNullability] java.lang.Class<*>?): @[FlexibleNullability] java.lang.reflect.Method? declared in java.lang.Class' type=@[FlexibleNullability] java.lang.reflect.Method? origin=null + $this: CALL 'public final fun (): java.lang.Class> [inline] declared in kotlin.jvm.JvmClassMappingKt' type=java.lang.Class<.box.> origin=GET_PROPERTY + : .box. + $receiver: GET_VAR 'val impl: .box. [val] declared in .box' type=.box. origin=null + p0: CONST String type=kotlin.String value="m" + p1: VARARG type=kotlin.Array?>? varargElementType=@[FlexibleNullability] java.lang.Class<*>? + CALL 'public final fun (): java.lang.Class> declared in kotlin.jvm.JvmClassMappingKt' type=java.lang.Class origin=GET_PROPERTY + : kotlin.String + $receiver: CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB CLASS name:String modality:FINAL visibility:public superTypes:[kotlin.Comparable; kotlin.CharSequence; java.io.Serializable]' type=kotlin.reflect.KClass + VAR name:parameter type:@[FlexibleNullability] java.lang.reflect.Parameter? [val] + CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=@[FlexibleNullability] java.lang.reflect.Parameter? origin=GET_ARRAY_ELEMENT + $this: TYPE_OP type=kotlin.Array<@[FlexibleNullability] java.lang.reflect.Parameter?> origin=IMPLICIT_CAST typeOperand=kotlin.Array<@[FlexibleNullability] java.lang.reflect.Parameter?> + TYPE_OP type=kotlin.Array origin=IMPLICIT_NOTNULL typeOperand=kotlin.Array + CALL 'public open fun getParameters (): @[FlexibleNullability] kotlin.Array? [fake_override] declared in java.lang.reflect.Method' type=@[FlexibleNullability] kotlin.Array? origin=GET_PROPERTY + $this: TYPE_OP type=java.lang.reflect.Method origin=IMPLICIT_NOTNULL typeOperand=java.lang.reflect.Method + GET_VAR 'val method: @[FlexibleNullability] java.lang.reflect.Method? [val] declared in .box' type=@[FlexibleNullability] java.lang.reflect.Method? origin=null + index: CONST Int type=kotlin.Int value=0 + VAR name:size type:kotlin.Int [val] + CALL 'public final fun (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY + $this: TYPE_OP type=kotlin.Array<@[FlexibleNullability] kotlin.Annotation?> origin=IMPLICIT_CAST typeOperand=kotlin.Array<@[FlexibleNullability] kotlin.Annotation?> + TYPE_OP type=kotlin.Array origin=IMPLICIT_NOTNULL typeOperand=kotlin.Array + CALL 'public open fun getAnnotations (): @[FlexibleNullability] kotlin.Array? declared in java.lang.reflect.Parameter' type=@[FlexibleNullability] kotlin.Array? origin=GET_PROPERTY + $this: TYPE_OP type=java.lang.reflect.Parameter origin=IMPLICIT_NOTNULL typeOperand=java.lang.reflect.Parameter + GET_VAR 'val parameter: @[FlexibleNullability] java.lang.reflect.Parameter? [val] declared in .box' type=@[FlexibleNullability] java.lang.reflect.Parameter? origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val size: kotlin.Int [val] declared in .box' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=1 + then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + STRING_CONCATENATION type=kotlin.String + CONST String type=kotlin.String value="ERR: " + GET_VAR 'val size: kotlin.Int [val] declared in .box' type=kotlin.Int origin=null + CLASS ANNOTATION_CLASS name:Ann modality:OPEN visibility:public superTypes:[kotlin.Annotation] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Ann + CONSTRUCTOR visibility:public <> () returnType:.Ann [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Ann modality:OPEN visibility:public superTypes:[kotlin.Annotation]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS INTERFACE name:I modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.I + FUN name:m visibility:public modality:OPEN <> ($this:.I, s:kotlin.String) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.I + VALUE_PARAMETER name:s index:0 type:kotlin.String + annotations: + Ann + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt new file mode 100644 index 00000000000..1f44337bffa --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt @@ -0,0 +1,22 @@ +// SKIP_KLIB_TEST +// WITH_REFLECT +// FULL_JDK + +fun box(): String { + val impl = object : I { + } + + val method = impl.javaClass.getMethod("m", String::class.java) + val parameter = method.parameters[0] + + val size = parameter.annotations.size + if (size == 1) return "OK" + return "ERR: $size" +} + +annotation class Ann + +interface I { + fun m(@Ann s: String) { + } +} diff --git a/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt.txt b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt.txt new file mode 100644 index 00000000000..2af8d94831c --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt.txt @@ -0,0 +1,36 @@ +fun box(): String { + val impl: = { // BLOCK + local class : I { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + () + } + val method: @FlexibleNullability Method? = impl.<>().getMethod(p0 = "m", p1 = [String::class.()]) + val parameter: @FlexibleNullability Parameter? = method /*!! Method */.getParameters() /*!! Array */ /*as Array<@FlexibleNullability Parameter?> */.get(index = 0) + val size: Int = parameter /*!! Parameter */.getAnnotations() /*!! Array */ /*as Array<@FlexibleNullability Annotation?> */.() + when { + EQEQ(arg0 = size, arg1 = 1) -> return "OK" + } + return "ERR: " + size +} + +open annotation class Ann : Annotation { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + +interface I { + fun m(@Ann s: String) { + } + +} 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 110a19d6e74..26b39fd2035 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 @@ -17817,6 +17817,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/falsePositiveBoundSmartcast.kt"); } + @Test + @TestMetadata("findAnnotationOnDefaultMethodParameter.kt") + public void testFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/codegen/box/fir/findAnnotationOnDefaultMethodParameter.kt"); + } + @Test @TestMetadata("Fir2IrClassifierStorage.kt") public void testFir2IrClassifierStorage() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 31f0e16b79b..4b24eba3bfa 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2632,6 +2632,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.kt"); } + @Test + @TestMetadata("reflectFindAnnotationOnDefaultMethodParameter.kt") + public void testReflectFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt"); + } + @Test @TestMetadata("reflectGetOnNullableTypeAlias.kt") public void testReflectGetOnNullableTypeAlias() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java index 872ea9b6f4e..f090f53d776 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibTextTestCaseGenerated.java @@ -1932,6 +1932,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/firProblems/recursiveCapturedTypeInPropertyReference.kt"); } + @TestMetadata("reflectFindAnnotationOnDefaultMethodParameter.kt") + public void testReflectFindAnnotationOnDefaultMethodParameter() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/reflectFindAnnotationOnDefaultMethodParameter.kt"); + } + @TestMetadata("reflectGetOnNullableTypeAlias.kt") public void testReflectGetOnNullableTypeAlias() throws Exception { runTest("compiler/testData/ir/irText/firProblems/reflectGetOnNullableTypeAlias.kt");