Skip to content

Commit e717cd7

Browse files
authored
Merge pull request #70165 from xedin/rdar118934711-5.10
[5.10][TypeChecker] Prevent invalid attribute on accessor from failing if i…
2 parents 4261fcf + 39985ed commit e717cd7

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
@@ -438,29 +438,38 @@ GlobalActorAttributeRequest::evaluate(
438438
.warnUntilSwiftVersion(6)
439439
.fixItRemove(globalActorAttr->getRangeWithAt());
440440

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

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

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

0 commit comments

Comments
 (0)