[FIR2IR] Set type arguments on annotation calls
#KT-58553 Fixed
This commit is contained in:
committed by
Space Team
parent
8091aebbc7
commit
9ca9fc9c68
+19
-8
@@ -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<FirTypeProjection>?,
|
||||
typeParameters: List<FirTypeParameter>?,
|
||||
): 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)
|
||||
|
||||
|
||||
@@ -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<ARG>(42)
|
||||
@Test2<String, String>(38)
|
||||
@Test3<String, C<String>>(Test1(39))
|
||||
@Test4([Test3(Test1(40)), Test3(Test1(50)), Test3(Test1(60))])
|
||||
@Test4([Test3<Int, C<Int>>(Test1(40)), Test3<Int, C<Int>>(Test1(50)), Test3<Int, C<Int>>(Test1(60))])
|
||||
//@Test5<ARG>(*arrayOf(Test3(Test1(70))), *arrayOf(Test3(Test1(80)))) <-- KT-45414
|
||||
class O {
|
||||
fun test(): String = "O"
|
||||
@@ -43,7 +39,7 @@ import ann.*
|
||||
@Test1<ARG>(24)
|
||||
@Test2<String, String>(83)
|
||||
@Test3<String, C<String>>(Test1(93))
|
||||
@Test4([Test3(Test1(44)), Test3(Test1(55)), Test3(Test1(66))])
|
||||
@Test4([Test3<Int, C<Int>>(Test1(44)), Test3<Int, C<Int>>(Test1(55)), Test3<Int, C<Int>>(Test1(66))])
|
||||
//@Test5<ARG>(*arrayOf(Test3(Test1(77))), *arrayOf(Test3(Test1(88)))) <-- KT-45414
|
||||
class K {
|
||||
fun test(): String = "K"
|
||||
|
||||
+4
-4
@@ -219,11 +219,11 @@ FILE fqName:ann fileName:/genericAnnotationClasses.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:CC modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
annotations:
|
||||
Test1(x = '42')
|
||||
Test2(x = '38')
|
||||
Test3(x = Test1<ann.I<ann.C<kotlin.String>>>(x = '39'))
|
||||
Test1<ann.ARG>(x = '42')
|
||||
Test2<kotlin.String, kotlin.String>(x = '38')
|
||||
Test3<kotlin.String, ann.C<kotlin.String>>(x = Test1<ann.I<ann.C<kotlin.String>>>(x = '39'))
|
||||
Test4(x = [Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '40')), Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '50')), Test3<IrErrorType(null), IrErrorType(null)>(x = Test1<IrErrorType(null)>(x = '60'))])
|
||||
Test5(xs = [Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '70')), Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '80'))])
|
||||
Test5<ann.ARG>(xs = [Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '70')), Test3<ann.ARG, ann.C<ann.ARG>>(x = Test1<ann.I<ann.C<ann.ARG>>>(x = '80'))])
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:ann.CC
|
||||
CONSTRUCTOR visibility:public <> () returnType:ann.CC [primary]
|
||||
BLOCK_BODY
|
||||
|
||||
+4
-4
@@ -87,11 +87,11 @@ open annotation class Test5<T : Any?> : Annotation {
|
||||
|
||||
}
|
||||
|
||||
@Test1(x = 42)
|
||||
@Test2(x = 38)
|
||||
@Test3(x = Test1<I<C<String>>>(x = 39))
|
||||
@Test1<ARG>(x = 42)
|
||||
@Test2<String, String>(x = 38)
|
||||
@Test3<String, C<String>>(x = Test1<I<C<String>>>(x = 39))
|
||||
@Test4(x = [Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 40)), Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 50)), Test3<ErrorType, ErrorType>(x = Test1<ErrorType>(x = 60))])
|
||||
@Test5(xs = [Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 70)), Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 80))])
|
||||
@Test5<ARG>(xs = [Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 70)), Test3<ARG, C<ARG>>(x = Test1<I<C<ARG>>>(x = 80))])
|
||||
class CC {
|
||||
constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
|
||||
Reference in New Issue
Block a user