[AA FIR] FirLazyAnnotationTransformer: fix resolve contract violation

We can't reduce resolve to COMPILER_REQUIRED_ANNOTATIONS phase for
annotations with arguments, because currently they don't have
argument mapping

```stracktrace
org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: By now the annotations argument mapping should have been resolved
	at org.jetbrains.kotlin.analysis.api.fir.annotations.FirAnnotationUtilsKt.mapAnnotationParameters(firAnnotationUtils.kt:137)
	at org.jetbrains.kotlin.analysis.api.fir.FirUtilsKt.toKtAnnotationApplication(FirUtils.kt:79)
	at org.jetbrains.kotlin.analysis.api.fir.annotations.FirAnnotationUtilsKt.annotationsByClassId(firAnnotationUtils.kt:60)
	at org.jetbrains.kotlin.analysis.api.fir.annotations.FirAnnotationUtilsKt.annotationsByClassId$default(firAnnotationUtils.kt:46)
```

^KT-57424 Fixed
This commit is contained in:
Dmitrii Gridin
2023-03-20 15:05:30 +01:00
parent 9892a49c4b
commit c046bedfc2
7 changed files with 49 additions and 21 deletions
@@ -49,27 +49,15 @@ internal fun annotationsByClassId(
useSiteTargetFilter: AnnotationUseSiteTargetFilter,
useSiteSession: FirSession,
annotationContainer: FirAnnotationContainer = firSymbol.fir,
): List<KtAnnotationApplicationWithArgumentsInfo> =
if (firSymbol.isFromCompilerRequiredAnnotationsPhase(classId)) {
buildList {
// this loop by index is required to avoid possible ConcurrentModificationException
val annotations = annotationContainer.resolvedCompilerRequiredAnnotations(firSymbol)
for (index in annotations.indices) {
val annotation = annotations[index]
if (useSiteTargetFilter.isAllowed(annotation.useSiteTarget) && annotation.toAnnotationClassIdSafe(useSiteSession) == classId) {
add(annotation.toKtAnnotationApplication(useSiteSession, index))
}
}
): List<KtAnnotationApplicationWithArgumentsInfo> {
return annotationContainer.resolvedAnnotationsWithArguments(firSymbol).mapIndexedNotNull { index, annotation ->
if (!useSiteTargetFilter.isAllowed(annotation.useSiteTarget) || annotation.toAnnotationClassId(useSiteSession) != classId) {
return@mapIndexedNotNull null
}
} else {
annotationContainer.resolvedAnnotationsWithArguments(firSymbol).mapIndexedNotNull { index, annotation ->
if (!useSiteTargetFilter.isAllowed(annotation.useSiteTarget) || annotation.toAnnotationClassId(useSiteSession) != classId) {
return@mapIndexedNotNull null
}
annotation.toKtAnnotationApplication(useSiteSession, index)
}
annotation.toKtAnnotationApplication(useSiteSession, index)
}
}
internal fun annotations(
firSymbol: FirBasedSymbol<*>,