|
16 | 16 | //===----------------------------------------------------------------------===//
|
17 | 17 | #include "TypeCheckObjC.h"
|
18 | 18 | #include "TypeChecker.h"
|
| 19 | +#include "TypeCheckConcurrency.h" |
19 | 20 | #include "TypeCheckProtocol.h"
|
20 | 21 | #include "swift/AST/ASTContext.h"
|
21 | 22 | #include "swift/AST/Decl.h"
|
@@ -368,6 +369,32 @@ static bool checkObjCInForeignClassContext(const ValueDecl *VD,
|
368 | 369 | return true;
|
369 | 370 | }
|
370 | 371 |
|
| 372 | +/// Actor-isolated declarations cannot be @objc. |
| 373 | +static bool checkObjCActorIsolation(const ValueDecl *VD, |
| 374 | + ObjCReason Reason) { |
| 375 | + // Check actor isolation. |
| 376 | + bool Diagnose = shouldDiagnoseObjCReason(Reason, VD->getASTContext()); |
| 377 | + |
| 378 | + switch (getActorIsolation(const_cast<ValueDecl *>(VD))) { |
| 379 | + case ActorIsolation::ActorInstance: |
| 380 | + // Actor-isolated functions cannot be @objc. |
| 381 | + if (Diagnose) { |
| 382 | + VD->diagnose( |
| 383 | + diag::actor_isolated_objc, VD->getDescriptiveKind(), VD->getName()); |
| 384 | + describeObjCReason(VD, Reason); |
| 385 | + if (auto FD = dyn_cast<FuncDecl>(VD)) { |
| 386 | + addAsyncNotes(const_cast<FuncDecl *>(FD)); |
| 387 | + } |
| 388 | + } |
| 389 | + return true; |
| 390 | + |
| 391 | + case ActorIsolation::ActorPrivileged: |
| 392 | + case ActorIsolation::Independent: |
| 393 | + case ActorIsolation::Unspecified: |
| 394 | + return false; |
| 395 | + } |
| 396 | +} |
| 397 | + |
371 | 398 | static VersionRange getMinOSVersionForClassStubs(const llvm::Triple &target) {
|
372 | 399 | if (target.isMacOSX())
|
373 | 400 | return VersionRange::allGTE(llvm::VersionTuple(10, 15, 0));
|
@@ -512,6 +539,8 @@ bool swift::isRepresentableInObjC(
|
512 | 539 | return false;
|
513 | 540 | if (checkObjCInExtensionContext(AFD, Diagnose))
|
514 | 541 | return false;
|
| 542 | + if (checkObjCActorIsolation(AFD, Reason)) |
| 543 | + return false; |
515 | 544 |
|
516 | 545 | if (AFD->isOperator()) {
|
517 | 546 | AFD->diagnose((isa<ProtocolDecl>(AFD->getDeclContext())
|
@@ -686,10 +715,12 @@ bool swift::isRepresentableInObjC(
|
686 | 715 | Type resultType = FD->mapTypeIntoContext(FD->getResultInterfaceType());
|
687 | 716 | if (auto tupleType = resultType->getAs<TupleType>()) {
|
688 | 717 | for (const auto &tupleElt : tupleType->getElements()) {
|
689 |
| - addCompletionHandlerParam(tupleElt.getType()); |
| 718 | + if (addCompletionHandlerParam(tupleElt.getType())) |
| 719 | + return false; |
690 | 720 | }
|
691 | 721 | } else {
|
692 |
| - addCompletionHandlerParam(resultType); |
| 722 | + if (addCompletionHandlerParam(resultType)) |
| 723 | + return false; |
693 | 724 | }
|
694 | 725 |
|
695 | 726 | // For a throwing asynchronous function, an Error? parameter is added
|
@@ -939,6 +970,8 @@ bool swift::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
|
939 | 970 |
|
940 | 971 | if (checkObjCInForeignClassContext(VD, Reason))
|
941 | 972 | return false;
|
| 973 | + if (checkObjCActorIsolation(VD, Reason)) |
| 974 | + return false; |
942 | 975 |
|
943 | 976 | if (!Diagnose || Result)
|
944 | 977 | return Result;
|
@@ -967,6 +1000,8 @@ bool swift::isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason) {
|
967 | 1000 | return false;
|
968 | 1001 | if (checkObjCWithGenericParams(SD, Reason))
|
969 | 1002 | return false;
|
| 1003 | + if (checkObjCActorIsolation(SD, Reason)) |
| 1004 | + return false; |
970 | 1005 |
|
971 | 1006 | // ObjC doesn't support class subscripts.
|
972 | 1007 | if (!SD->isInstanceMember()) {
|
|
0 commit comments