RestrictSuspension -> RestrictsSuspendExtensions
(cherry picked from commit 9e0c733)
This commit is contained in:
committed by
Stanislav Erokhin
parent
c73b0d7b76
commit
8968bc3dd6
+8
-8
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasRestrictSuspensionAnnotation
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasRestrictsSuspendExtensionsAnnotation
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||
@@ -67,7 +67,7 @@ object CoroutineSuspendCallChecker : CallChecker {
|
||||
// Here we only record enclosing function mapping (for backends purposes)
|
||||
context.trace.record(BindingContext.ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL, resolvedCall.call, enclosingSuspendFunction)
|
||||
|
||||
checkRestrictSuspension(enclosingSuspendFunction, resolvedCall, reportOn, context)
|
||||
checkRestrictsSuspendExtensions(enclosingSuspendFunction, resolvedCall, reportOn, context)
|
||||
}
|
||||
closestSuspensionLambdaDescriptor != null -> {
|
||||
val callElement = resolvedCall.call.callElement as KtExpression
|
||||
@@ -80,7 +80,7 @@ object CoroutineSuspendCallChecker : CallChecker {
|
||||
BindingContext.ENCLOSING_SUSPEND_LAMBDA_FOR_SUSPENSION_POINT, resolvedCall.call, closestSuspensionLambdaDescriptor
|
||||
)
|
||||
|
||||
checkRestrictSuspension(closestSuspensionLambdaDescriptor, resolvedCall, reportOn, context)
|
||||
checkRestrictsSuspendExtensions(closestSuspensionLambdaDescriptor, resolvedCall, reportOn, context)
|
||||
}
|
||||
else -> {
|
||||
context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn))
|
||||
@@ -110,7 +110,7 @@ fun checkCoroutinesFeature(languageVersionSettings: LanguageVersionSettings, dia
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkRestrictSuspension(
|
||||
private fun checkRestrictsSuspendExtensions(
|
||||
enclosingCallableDescriptor: CallableDescriptor,
|
||||
resolvedCall: ResolvedCall<*>,
|
||||
reportOn: PsiElement,
|
||||
@@ -118,8 +118,8 @@ private fun checkRestrictSuspension(
|
||||
) {
|
||||
val enclosingSuspendReceiverValue = enclosingCallableDescriptor.extensionReceiverParameter?.value ?: return
|
||||
|
||||
fun ReceiverValue.isRestrictSuspensionReceiver() = (type.supertypes() + type).any {
|
||||
it.constructor.declarationDescriptor?.hasRestrictSuspensionAnnotation() == true
|
||||
fun ReceiverValue.isRestrictsSuspendExtensionsReceiver() = (type.supertypes() + type).any {
|
||||
it.constructor.declarationDescriptor?.hasRestrictsSuspendExtensionsAnnotation() == true
|
||||
}
|
||||
|
||||
infix fun ReceiverValue.sameInstance(other: ReceiverValue?): Boolean {
|
||||
@@ -134,13 +134,13 @@ private fun checkRestrictSuspension(
|
||||
return this === (referenceTarget as? CallableDescriptor)?.extensionReceiverParameter?.value
|
||||
}
|
||||
|
||||
if (!enclosingSuspendReceiverValue.isRestrictSuspensionReceiver()) return
|
||||
if (!enclosingSuspendReceiverValue.isRestrictsSuspendExtensionsReceiver()) return
|
||||
|
||||
// member of suspend receiver
|
||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.dispatchReceiver) return
|
||||
|
||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.extensionReceiver &&
|
||||
resolvedCall.candidateDescriptor.extensionReceiverParameter!!.value.isRestrictSuspensionReceiver()) return
|
||||
resolvedCall.candidateDescriptor.extensionReceiverParameter!!.value.isRestrictsSuspendExtensionsReceiver()) return
|
||||
|
||||
context.trace.report(Errors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL.on(reportOn))
|
||||
}
|
||||
Reference in New Issue
Block a user