[FIR] Forbid all use-site targets of FirTypeRef annotations

This commit is contained in:
Nikolay Lunyak
2023-03-06 10:27:47 +02:00
committed by Space Team
parent 93ba0c3e70
commit 1378d730d6
13 changed files with 39 additions and 49 deletions
@@ -26,21 +26,17 @@ object FirTypeAnnotationChecker : FirTypeRefChecker() {
for (annotation in typeRef.annotations) {
if (annotation.source == null) continue
val useSiteTarget = annotation.useSiteTarget
val annotationTargets = annotation.getAllowedAnnotationTargets(context.session)
// Annotations with `@receiver:` go
// Annotations like `@receiver:` go
// into FirReceiverParameter, not FirTypeRef
if (useSiteTarget == AnnotationUseSiteTarget.RECEIVER) {
if (useSiteTarget != null) {
reporter.reportOn(
annotation.source, FirErrors.WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET,
"type usage", useSiteTarget.renderName, context
)
}
val annotationTargets = annotation.getAllowedAnnotationTargets(context.session)
if (KotlinTarget.TYPE !in annotationTargets) {
if (useSiteTarget == null || KotlinTarget.USE_SITE_MAPPING[useSiteTarget] !in annotationTargets) {
reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context)
}
} else if (KotlinTarget.TYPE !in annotationTargets) {
reporter.reportOn(annotation.source, FirErrors.WRONG_ANNOTATION_TARGET, "type usage", context)
}
if (annotation.toAnnotationClassId(context.session) == StandardClassIds.Annotations.ExtensionFunctionType) {
if (!typeRef.type.isSomeFunctionType(context.session)) {