Skip to content

Commit 6ad21e5

Browse files
authored
Merge pull request #70163 from xedin/rdar118934711
[TypeChecker] Prevent invalid attribute on accessor from failing if i…
2 parents df83676 + 8918e2e commit 6ad21e5

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,29 +439,38 @@ GlobalActorAttributeRequest::evaluate(
439439
.warnUntilSwiftVersion(6)
440440
.fixItRemove(globalActorAttr->getRangeWithAt());
441441

442+
auto &ctx = decl->getASTContext();
442443
auto *storage = accessor->getStorage();
443444
// Let's suggest to move the attribute to the storage if
444445
// this is an accessor/addressor of a property of subscript.
445446
if (storage->getDeclContext()->isTypeContext()) {
446-
// If enclosing declaration has a global actor,
447-
// skip the suggestion.
448-
if (storage->getGlobalActorAttr())
449-
return llvm::None;
450-
451-
// Global actor attribute cannot be applied to
452-
// an instance stored property of a struct.
453-
if (auto *var = dyn_cast<VarDecl>(storage)) {
454-
if (isStoredInstancePropertyOfStruct(var))
455-
return llvm::None;
456-
}
447+
auto canMoveAttr = [&]() {
448+
// If enclosing declaration has a global actor,
449+
// skip the suggestion.
450+
if (storage->getGlobalActorAttr())
451+
return false;
452+
453+
// Global actor attribute cannot be applied to
454+
// an instance stored property of a struct.
455+
if (auto *var = dyn_cast<VarDecl>(storage)) {
456+
return !isStoredInstancePropertyOfStruct(var);
457+
}
458+
459+
return true;
460+
};
457461

458-
decl->diagnose(diag::move_global_actor_attr_to_storage_decl, storage)
459-
.fixItInsert(
460-
storage->getAttributeInsertionLoc(/*forModifier=*/false),
461-
llvm::Twine("@", result->second->getNameStr()).str());
462+
if (canMoveAttr()) {
463+
decl->diagnose(diag::move_global_actor_attr_to_storage_decl,
464+
storage)
465+
.fixItInsert(
466+
storage->getAttributeInsertionLoc(/*forModifier=*/false),
467+
llvm::Twine("@", result->second->getNameStr()).str());
468+
}
462469
}
463470

464-
return llvm::None;
471+
// In Swift 6, once the diag above is an error, it is disallowed.
472+
if (ctx.isSwiftVersionAtLeast(6))
473+
return llvm::None;
465474
}
466475
}
467476
// Functions are okay.

0 commit comments

Comments
 (0)