K1:report warning on OptIn usages inside SAM constructor #KT-47708 Fixed

This commit is contained in:
Mikhail Glukhikh
2022-05-31 13:38:43 +02:00
committed by Space
parent 8fefa8a57b
commit 6fc27c22f4
4 changed files with 20 additions and 2 deletions
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.resolve.deprecation.DeprecationSettings
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.AbbreviatedType
import org.jetbrains.kotlin.types.KotlinType
@@ -97,6 +98,15 @@ class OptInUsageChecker(project: Project) : CallChecker {
return
}
}
if (resultingDescriptor is SamConstructorDescriptor) {
// KT-47708 special case (warning only)
val methodDescriptor = resultingDescriptor.getSingleAbstractMethod()
val samOptIns = methodDescriptor.loadOptIns(moduleAnnotationsResolver, context.languageVersionSettings)
.map { (fqName, _, message) ->
OptInDescription(fqName, OptInDescription.Severity.WARNING, message)
}
reportNotAllowedOptIns(samOptIns, reportOn, context)
}
reportNotAllowedOptIns(optIns, reportOn, context)
}