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.psi.KtThisExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
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.inline.InlineUtil
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||||
@@ -67,7 +67,7 @@ object CoroutineSuspendCallChecker : CallChecker {
|
|||||||
// Here we only record enclosing function mapping (for backends purposes)
|
// Here we only record enclosing function mapping (for backends purposes)
|
||||||
context.trace.record(BindingContext.ENCLOSING_SUSPEND_FUNCTION_FOR_SUSPEND_FUNCTION_CALL, resolvedCall.call, enclosingSuspendFunction)
|
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 -> {
|
closestSuspensionLambdaDescriptor != null -> {
|
||||||
val callElement = resolvedCall.call.callElement as KtExpression
|
val callElement = resolvedCall.call.callElement as KtExpression
|
||||||
@@ -80,7 +80,7 @@ object CoroutineSuspendCallChecker : CallChecker {
|
|||||||
BindingContext.ENCLOSING_SUSPEND_LAMBDA_FOR_SUSPENSION_POINT, resolvedCall.call, closestSuspensionLambdaDescriptor
|
BindingContext.ENCLOSING_SUSPEND_LAMBDA_FOR_SUSPENSION_POINT, resolvedCall.call, closestSuspensionLambdaDescriptor
|
||||||
)
|
)
|
||||||
|
|
||||||
checkRestrictSuspension(closestSuspensionLambdaDescriptor, resolvedCall, reportOn, context)
|
checkRestrictsSuspendExtensions(closestSuspensionLambdaDescriptor, resolvedCall, reportOn, context)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
context.trace.report(Errors.ILLEGAL_SUSPEND_FUNCTION_CALL.on(reportOn))
|
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,
|
enclosingCallableDescriptor: CallableDescriptor,
|
||||||
resolvedCall: ResolvedCall<*>,
|
resolvedCall: ResolvedCall<*>,
|
||||||
reportOn: PsiElement,
|
reportOn: PsiElement,
|
||||||
@@ -118,8 +118,8 @@ private fun checkRestrictSuspension(
|
|||||||
) {
|
) {
|
||||||
val enclosingSuspendReceiverValue = enclosingCallableDescriptor.extensionReceiverParameter?.value ?: return
|
val enclosingSuspendReceiverValue = enclosingCallableDescriptor.extensionReceiverParameter?.value ?: return
|
||||||
|
|
||||||
fun ReceiverValue.isRestrictSuspensionReceiver() = (type.supertypes() + type).any {
|
fun ReceiverValue.isRestrictsSuspendExtensionsReceiver() = (type.supertypes() + type).any {
|
||||||
it.constructor.declarationDescriptor?.hasRestrictSuspensionAnnotation() == true
|
it.constructor.declarationDescriptor?.hasRestrictsSuspendExtensionsAnnotation() == true
|
||||||
}
|
}
|
||||||
|
|
||||||
infix fun ReceiverValue.sameInstance(other: ReceiverValue?): Boolean {
|
infix fun ReceiverValue.sameInstance(other: ReceiverValue?): Boolean {
|
||||||
@@ -134,13 +134,13 @@ private fun checkRestrictSuspension(
|
|||||||
return this === (referenceTarget as? CallableDescriptor)?.extensionReceiverParameter?.value
|
return this === (referenceTarget as? CallableDescriptor)?.extensionReceiverParameter?.value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!enclosingSuspendReceiverValue.isRestrictSuspensionReceiver()) return
|
if (!enclosingSuspendReceiverValue.isRestrictsSuspendExtensionsReceiver()) return
|
||||||
|
|
||||||
// member of suspend receiver
|
// member of suspend receiver
|
||||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.dispatchReceiver) return
|
if (enclosingSuspendReceiverValue sameInstance resolvedCall.dispatchReceiver) return
|
||||||
|
|
||||||
if (enclosingSuspendReceiverValue sameInstance resolvedCall.extensionReceiver &&
|
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))
|
context.trace.report(Errors.ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL.on(reportOn))
|
||||||
}
|
}
|
||||||
+1
-1
@@ -5,7 +5,7 @@ interface SuperInterface {
|
|||||||
suspend fun String.superExtFun() {}
|
suspend fun String.superExtFun() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension
|
@kotlin.coroutines.RestrictsSuspendExtensions
|
||||||
open class RestrictedController : SuperInterface {
|
open class RestrictedController : SuperInterface {
|
||||||
suspend fun memberFun() {}
|
suspend fun memberFun() {}
|
||||||
suspend fun String.memberExtFun() {}
|
suspend fun String.memberExtFun() {}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ public fun generate2(/*0*/ f: suspend RestrictedController.() -> kotlin.Unit): k
|
|||||||
public fun generate3(/*0*/ f: suspend SubClass.() -> kotlin.Unit): kotlin.Unit
|
public fun generate3(/*0*/ f: suspend SubClass.() -> kotlin.Unit): kotlin.Unit
|
||||||
public fun kotlin.String.test(): kotlin.Unit
|
public fun kotlin.String.test(): kotlin.Unit
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension public open class RestrictedController : SuperInterface {
|
@kotlin.coroutines.RestrictsSuspendExtensions public open class RestrictedController : SuperInterface {
|
||||||
public constructor RestrictedController()
|
public constructor RestrictedController()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
interface SuperInterface
|
interface SuperInterface
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension
|
@kotlin.coroutines.RestrictsSuspendExtensions
|
||||||
open class RestrictedController : SuperInterface
|
open class RestrictedController : SuperInterface
|
||||||
|
|
||||||
class SubClass : RestrictedController()
|
class SubClass : RestrictedController()
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ public final class A {
|
|||||||
public final suspend fun SuperInterface.memExtSuper(): kotlin.Unit
|
public final suspend fun SuperInterface.memExtSuper(): kotlin.Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension public open class RestrictedController : SuperInterface {
|
@kotlin.coroutines.RestrictsSuspendExtensions public open class RestrictedController : SuperInterface {
|
||||||
public constructor RestrictedController()
|
public constructor RestrictedController()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
interface SuperInterface
|
interface SuperInterface
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension
|
@kotlin.coroutines.RestrictsSuspendExtensions
|
||||||
open class RestrictedController : SuperInterface
|
open class RestrictedController : SuperInterface
|
||||||
|
|
||||||
class SubClass : RestrictedController()
|
class SubClass : RestrictedController()
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ public final class A {
|
|||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension public open class RestrictedController : SuperInterface {
|
@kotlin.coroutines.RestrictsSuspendExtensions public open class RestrictedController : SuperInterface {
|
||||||
public constructor RestrictedController()
|
public constructor RestrictedController()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension
|
@kotlin.coroutines.RestrictsSuspendExtensions
|
||||||
class RestrictedController {
|
class RestrictedController {
|
||||||
suspend fun member() {}
|
suspend fun member() {}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ public fun test(): kotlin.Unit
|
|||||||
public suspend fun RestrictedController.extension(): kotlin.Unit
|
public suspend fun RestrictedController.extension(): kotlin.Unit
|
||||||
public suspend fun RestrictedController.l(): kotlin.Unit
|
public suspend fun RestrictedController.l(): kotlin.Unit
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension public final class RestrictedController {
|
@kotlin.coroutines.RestrictsSuspendExtensions public final class RestrictedController {
|
||||||
public constructor RestrictedController()
|
public constructor RestrictedController()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
@kotlin.coroutines.RestrictSuspension
|
@kotlin.coroutines.RestrictsSuspendExtensions
|
||||||
class RestrictedController
|
class RestrictedController
|
||||||
|
|
||||||
suspend fun Any?.extFun() {}
|
suspend fun Any?.extFun() {}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ public suspend fun suspendFun(): kotlin.Unit
|
|||||||
public fun test(): kotlin.Unit
|
public fun test(): kotlin.Unit
|
||||||
public suspend fun kotlin.Any?.extFun(): kotlin.Unit
|
public suspend fun kotlin.Any?.extFun(): kotlin.Unit
|
||||||
|
|
||||||
@kotlin.coroutines.RestrictSuspension public final class RestrictedController {
|
@kotlin.coroutines.RestrictsSuspendExtensions public final class RestrictedController {
|
||||||
public constructor RestrictedController()
|
public constructor RestrictedController()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.descriptorUtil
|
package org.jetbrains.kotlin.resolve.descriptorUtil
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
@@ -33,7 +32,7 @@ val LOW_PRIORITY_IN_OVERLOAD_RESOLUTION_FQ_NAME = FqName("kotlin.internal.LowPri
|
|||||||
private val HIDES_MEMBERS_ANNOTATION_FQ_NAME = FqName("kotlin.internal.HidesMembers")
|
private val HIDES_MEMBERS_ANNOTATION_FQ_NAME = FqName("kotlin.internal.HidesMembers")
|
||||||
private val ONLY_INPUT_TYPES_FQ_NAME = FqName("kotlin.internal.OnlyInputTypes")
|
private val ONLY_INPUT_TYPES_FQ_NAME = FqName("kotlin.internal.OnlyInputTypes")
|
||||||
private val DYNAMIC_EXTENSION_FQ_NAME = FqName("kotlin.internal.DynamicExtension")
|
private val DYNAMIC_EXTENSION_FQ_NAME = FqName("kotlin.internal.DynamicExtension")
|
||||||
private val RESTRICT_SUSPENSION_FQ_NAME = FqName("kotlin.coroutines.RestrictSuspension")
|
private val RESTRICTS_SUSPEND_EXTENSIONS_FQ_NAME = FqName("kotlin.coroutines.RestrictsSuspendExtensions")
|
||||||
|
|
||||||
// @HidesMembers annotation only has effect for members with these names
|
// @HidesMembers annotation only has effect for members with these names
|
||||||
val HIDES_MEMBERS_NAME_LIST = setOf(Name.identifier("forEach"))
|
val HIDES_MEMBERS_NAME_LIST = setOf(Name.identifier("forEach"))
|
||||||
@@ -51,7 +50,7 @@ fun CallableDescriptor.hasLowPriorityInOverloadResolution(): Boolean = annotatio
|
|||||||
|
|
||||||
fun CallableDescriptor.hasHidesMembersAnnotation(): Boolean = annotations.hasAnnotation(HIDES_MEMBERS_ANNOTATION_FQ_NAME)
|
fun CallableDescriptor.hasHidesMembersAnnotation(): Boolean = annotations.hasAnnotation(HIDES_MEMBERS_ANNOTATION_FQ_NAME)
|
||||||
fun CallableDescriptor.hasDynamicExtensionAnnotation(): Boolean = annotations.hasAnnotation(DYNAMIC_EXTENSION_FQ_NAME)
|
fun CallableDescriptor.hasDynamicExtensionAnnotation(): Boolean = annotations.hasAnnotation(DYNAMIC_EXTENSION_FQ_NAME)
|
||||||
fun ClassifierDescriptor.hasRestrictSuspensionAnnotation(): Boolean = annotations.hasAnnotation(RESTRICT_SUSPENSION_FQ_NAME)
|
fun ClassifierDescriptor.hasRestrictsSuspendExtensionsAnnotation(): Boolean = annotations.hasAnnotation(RESTRICTS_SUSPEND_EXTENSIONS_FQ_NAME)
|
||||||
|
|
||||||
fun TypeParameterDescriptor.hasOnlyInputTypesAnnotation(): Boolean = annotations.hasAnnotation(ONLY_INPUT_TYPES_FQ_NAME)
|
fun TypeParameterDescriptor.hasOnlyInputTypesAnnotation(): Boolean = annotations.hasAnnotation(ONLY_INPUT_TYPES_FQ_NAME)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user