diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index a3d35bce1be..0af3d4ae101 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -675,7 +675,7 @@ class CallAndReferenceGenerator( IrConstructorCallImpl( startOffset, endOffset, type, irConstructor, valueArgumentsCount = irConstructor.owner.valueParameters.size, - typeArgumentsCount = 0, + typeArgumentsCount = annotation.typeArguments.size, constructorTypeArgumentsCount = 0 ) } @@ -693,7 +693,10 @@ class CallAndReferenceGenerator( } } return visitor.withAnnotationMode { - irConstructorCall.applyCallArguments(annotation.toAnnotationCall()) + val annotationCall = annotation.toAnnotationCall() + irConstructorCall + .applyCallArguments(annotationCall) + .applyTypeArguments(annotationCall?.typeArguments, null) } } @@ -1050,11 +1053,22 @@ class CallAndReferenceGenerator( } internal fun IrExpression.applyTypeArguments(access: FirQualifiedAccessExpression): IrExpression { + return applyTypeArguments( + access.typeArguments, + (access.calleeReference.toResolvedCallableSymbol()?.fir as? FirTypeParametersOwner)?.typeParameters + ) + } + + private fun IrExpression.applyTypeArguments( + typeArguments: List?, + typeParameters: List?, + ): IrExpression { if (this !is IrMemberAccessExpression<*>) return this - val argumentsCount = access.typeArguments.size + + val argumentsCount = typeArguments?.size ?: return this if (argumentsCount <= typeArgumentsCount) { - for ((index, argument) in access.typeArguments.withIndex()) { - val typeParameter = access.findTypeParameter(index) + for ((index, argument) in typeArguments.withIndex()) { + val typeParameter = typeParameters?.get(index) val argumentFirType = (argument as FirTypeProjectionWithVariance).typeRef val argumentIrType = if (typeParameter?.isReified == true) { argumentFirType.approximateDeclarationType( @@ -1078,9 +1092,6 @@ class CallAndReferenceGenerator( } } - private fun FirQualifiedAccessExpression.findTypeParameter(index: Int): FirTypeParameter? = - ((calleeReference as? FirResolvedNamedReference)?.resolvedSymbol?.fir as? FirTypeParametersOwner)?.typeParameters?.get(index) - private fun FirQualifiedAccessExpression.findIrDispatchReceiver(explicitReceiverExpression: IrExpression?): IrExpression? = findIrReceiver(explicitReceiverExpression, isDispatch = true) diff --git a/compiler/testData/codegen/box/annotations/genericAnnotations.kt b/compiler/testData/codegen/box/annotations/genericAnnotations.kt index 5a72ca035b6..0049ffd732d 100644 --- a/compiler/testData/codegen/box/annotations/genericAnnotations.kt +++ b/compiler/testData/codegen/box/annotations/genericAnnotations.kt @@ -1,7 +1,3 @@ -// IGNORE_LEAKED_INTERNAL_TYPES: KT-54517 -// IGNORE_BACKEND_K2: JS_IR -// KT-58553 -// IGNORE_BACKEND_K2: NATIVE // MODULE: lib // FILE: l1.kt package ann @@ -29,7 +25,7 @@ import ann.* @Test1(42) @Test2(38) @Test3>(Test1(39)) -@Test4([Test3(Test1(40)), Test3(Test1(50)), Test3(Test1(60))]) +@Test4([Test3>(Test1(40)), Test3>(Test1(50)), Test3>(Test1(60))]) //@Test5(*arrayOf(Test3(Test1(70))), *arrayOf(Test3(Test1(80)))) <-- KT-45414 class O { fun test(): String = "O" @@ -43,7 +39,7 @@ import ann.* @Test1(24) @Test2(83) @Test3>(Test1(93)) -@Test4([Test3(Test1(44)), Test3(Test1(55)), Test3(Test1(66))]) +@Test4([Test3>(Test1(44)), Test3>(Test1(55)), Test3>(Test1(66))]) //@Test5(*arrayOf(Test3(Test1(77))), *arrayOf(Test3(Test1(88)))) <-- KT-45414 class K { fun test(): String = "K" diff --git a/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.ir.txt b/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.ir.txt index 3d98bc18a9b..f7b5a1e303e 100644 --- a/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.ir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.ir.txt @@ -219,11 +219,11 @@ FILE fqName:ann fileName:/genericAnnotationClasses.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS CLASS name:CC modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: - Test1(x = '42') - Test2(x = '38') - Test3(x = Test1>>(x = '39')) + Test1(x = '42') + Test2(x = '38') + Test3>(x = Test1>>(x = '39')) Test4(x = [Test3(x = Test1(x = '40')), Test3(x = Test1(x = '50')), Test3(x = Test1(x = '60'))]) - Test5(xs = [Test3>(x = Test1>>(x = '70')), Test3>(x = Test1>>(x = '80'))]) + Test5(xs = [Test3>(x = Test1>>(x = '70')), Test3>(x = Test1>>(x = '80'))]) $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:ann.CC CONSTRUCTOR visibility:public <> () returnType:ann.CC [primary] BLOCK_BODY diff --git a/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.kt.txt b/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.kt.txt index 797e3b1fa1d..4c8fbd072ff 100644 --- a/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.kt.txt +++ b/compiler/testData/ir/irText/declarations/annotations/genericAnnotationClasses.fir.kt.txt @@ -87,11 +87,11 @@ open annotation class Test5 : Annotation { } -@Test1(x = 42) -@Test2(x = 38) -@Test3(x = Test1>>(x = 39)) +@Test1(x = 42) +@Test2(x = 38) +@Test3>(x = Test1>>(x = 39)) @Test4(x = [Test3(x = Test1(x = 40)), Test3(x = Test1(x = 50)), Test3(x = Test1(x = 60))]) -@Test5(xs = [Test3>(x = Test1>>(x = 70)), Test3>(x = Test1>>(x = 80))]) +@Test5(xs = [Test3>(x = Test1>>(x = 70)), Test3>(x = Test1>>(x = 80))]) class CC { constructor() /* primary */ { super/*Any*/()