Support instantiation of annotations with type parameters

By ignoring type parameters. Since type parameters in annotations are a
very limited feature, their sole use is to be able to specify them as
KClass argument: annotation class Foo<T: Any>(val bar: KClass<T>).
Since we can encounter type param only as a KClass type argument (and
never as a property type), simple approach of ignoring them works fine.
In that case, since we simply copy property types to synthetic
implementation class, its properties in IR start look like this:
annotation class FooImpl(override val bar: KClass<T of Foo>). This IR
seems to be not completely correct, since FooImpl.bar type contains T of
Foo param, which is out of its scope. However, so far I didn't
encounter any problems with this during testing and after MR discussion
this approach has been considered possible.

#KT-59558 Fixed
#KT-59036 Fixed
This commit is contained in:
Leonid Startsev
2023-07-13 12:29:36 +02:00
committed by Space Team
parent 8c795462e1
commit 648c1f4599
23 changed files with 322 additions and 7 deletions
@@ -483,6 +483,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/annotations/instances/annotationType.kt");
}
@TestMetadata("annotationWithTypeParameters.kt")
public void testAnnotationWithTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/annotationWithTypeParameters.kt");
}
@TestMetadata("annotationWithTypeParametersJvm.kt")
public void testAnnotationWithTypeParametersJvm() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/annotationWithTypeParametersJvm.kt");
}
@TestMetadata("annotationsUnsignedTypes.kt")
public void testAnnotationsUnsignedTypes() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/annotationsUnsignedTypes.kt");
@@ -518,6 +528,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/annotations/instances/multimoduleInlining.kt");
}
@TestMetadata("multimoduleTypeParams.kt")
public void testMultimoduleTypeParams() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/multimoduleTypeParams.kt");
}
@TestMetadata("multiplatformInstantiation.kt")
public void testMultiplatformInstantiation() throws Exception {
runTest("compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt");