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