From 8968bc3dd607cf33e6382e4d211e5b619f9aece9 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Thu, 15 Dec 2016 19:14:36 +0300 Subject: [PATCH] RestrictSuspension -> RestrictsSuspendExtensions (cherry picked from commit 9e0c733) --- .../calls/checkers/coroutineCallChecker.kt | 16 ++++++++-------- .../restrictSuspension/allMembersAllowed.kt | 2 +- .../restrictSuspension/allMembersAllowed.txt | 2 +- .../coroutines/restrictSuspension/extensions.kt | 2 +- .../coroutines/restrictSuspension/extensions.txt | 2 +- .../restrictSuspension/notRelatedFun.kt | 2 +- .../restrictSuspension/notRelatedFun.txt | 2 +- .../restrictSuspension/sameInstance.kt | 2 +- .../restrictSuspension/sameInstance.txt | 2 +- .../restrictSuspension/simpleForbidden.kt | 2 +- .../restrictSuspension/simpleForbidden.txt | 2 +- .../kotlin/resolve/annotationsForResolve.kt | 5 ++--- 12 files changed, 20 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt index fac0d1e1579..1f1baf542e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt @@ -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)) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.kt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.kt index 73427ad008d..5d61fc1bdf4 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.kt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.kt @@ -5,7 +5,7 @@ interface SuperInterface { suspend fun String.superExtFun() {} } -@kotlin.coroutines.RestrictSuspension +@kotlin.coroutines.RestrictsSuspendExtensions open class RestrictedController : SuperInterface { suspend fun memberFun() {} suspend fun String.memberExtFun() {} diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.txt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.txt index 559316cb938..7c65f4d7346 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.txt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/allMembersAllowed.txt @@ -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 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 open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.kt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.kt index 487892a8a1d..9648527bcc4 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.kt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.kt @@ -2,7 +2,7 @@ interface SuperInterface -@kotlin.coroutines.RestrictSuspension +@kotlin.coroutines.RestrictsSuspendExtensions open class RestrictedController : SuperInterface class SubClass : RestrictedController() diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.txt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.txt index 187df8ab4d0..67e9ee15e6b 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.txt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/extensions.txt @@ -20,7 +20,7 @@ public final class A { 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 open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.kt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.kt index 873187e2d50..e3b2725aeb8 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.kt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.kt @@ -2,7 +2,7 @@ interface SuperInterface -@kotlin.coroutines.RestrictSuspension +@kotlin.coroutines.RestrictsSuspendExtensions open class RestrictedController : SuperInterface class SubClass : RestrictedController() diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.txt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.txt index 4f6398a4832..d7f20469bd2 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.txt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/notRelatedFun.txt @@ -14,7 +14,7 @@ public final class A { 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 open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.kt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.kt index 75aa522f692..f785df621f5 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.kt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE -@kotlin.coroutines.RestrictSuspension +@kotlin.coroutines.RestrictsSuspendExtensions class RestrictedController { suspend fun member() {} } diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.txt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.txt index c08866af291..4743848c055 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.txt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/sameInstance.txt @@ -5,7 +5,7 @@ public fun test(): kotlin.Unit public suspend fun RestrictedController.extension(): 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 open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.kt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.kt index 05a2f4f199d..12ff77efd54 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.kt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.kt @@ -1,4 +1,4 @@ -@kotlin.coroutines.RestrictSuspension +@kotlin.coroutines.RestrictsSuspendExtensions class RestrictedController suspend fun Any?.extFun() {} diff --git a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.txt b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.txt index 27dc5442ca9..0257f0a205e 100644 --- a/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.txt +++ b/compiler/testData/diagnostics/tests/coroutines/restrictSuspension/simpleForbidden.txt @@ -5,7 +5,7 @@ public suspend fun suspendFun(): kotlin.Unit public fun test(): 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 open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt index 2470a4410fd..51bf01c1489 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.resolve.descriptorUtil import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor 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 ONLY_INPUT_TYPES_FQ_NAME = FqName("kotlin.internal.OnlyInputTypes") 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 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.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)