@@ -439,29 +439,38 @@ GlobalActorAttributeRequest::evaluate(
439
439
.warnUntilSwiftVersion (6 )
440
440
.fixItRemove (globalActorAttr->getRangeWithAt ());
441
441
442
+ auto &ctx = decl->getASTContext ();
442
443
auto *storage = accessor->getStorage ();
443
444
// Let's suggest to move the attribute to the storage if
444
445
// this is an accessor/addressor of a property of subscript.
445
446
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
+ };
457
461
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
+ }
462
469
}
463
470
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;
465
474
}
466
475
}
467
476
// Functions are okay.
0 commit comments