@@ -2033,11 +2033,11 @@ namespace {
20332033
20342034 // / Note when the enclosing context could be put on a global actor.
20352035 // FIXME: This should handle closures too.
2036- static bool missingGlobalActorOnContext (DeclContext *dc, Type globalActor) {
2036+ static bool missingGlobalActorOnContext (DeclContext *dc, Type globalActor, DiagnosticBehavior behavior ) {
20372037 // If we are in a synchronous function on the global actor,
20382038 // suggest annotating with the global actor itself.
20392039 if (auto fn = findAnnotatableFunction (dc)) {
2040- // Suppress this for accessories because you can't change the
2040+ // Suppress this for accessors because you can't change the
20412041 // actor isolation of an individual accessor. Arguably we could
20422042 // add this to the entire storage declaration, though.
20432043 // Suppress this for async functions out of caution; but don't
@@ -2056,6 +2056,7 @@ namespace {
20562056 fn->diagnose (diag::add_globalactor_to_function,
20572057 globalActor->getWithoutParens ().getString (),
20582058 fn, globalActor)
2059+ .limitBehavior (behavior)
20592060 .fixItInsert (fn->getAttributeInsertionLoc (false ),
20602061 diag::insert_globalactor_attr, globalActor);
20612062 return true ;
@@ -2079,14 +2080,14 @@ namespace {
20792080 // Add Fix-it for missing @SomeActor annotation
20802081 if (isolation.isGlobalActor ()) {
20812082 if (missingGlobalActorOnContext (
2082- const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor ())) {
2083+ const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor (), behavior )) {
20832084 behavior= DiagnosticBehavior::Note;
20842085 }
20852086 }
20862087
20872088 for (IsolationError error : errors) {
20882089 // Diagnose actor_isolated_non_self_reference as note
2089- // if we provide fix-it in missingGlobalActorOnContext
2090+ // if fix-it provided in missingGlobalActorOnContext
20902091 ctx.Diags .diagnose (error.loc , error.diag )
20912092 .limitBehavior (behavior);
20922093 }
@@ -2102,14 +2103,14 @@ namespace {
21022103 // Add Fix-it for missing @SomeActor annotation
21032104 if (isolation.isGlobalActor ()) {
21042105 if (missingGlobalActorOnContext (
2105- const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor ())) {
2106+ const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor (), behavior )) {
21062107 behavior= DiagnosticBehavior::Note;
21072108 }
21082109 }
21092110
21102111 for (IsolationError error : errors) {
2111- // Diagnose actor_isolated_non_self_reference as note
2112- // if we provide fix-it in missingGlobalActorOnContext
2112+ // Diagnose actor_isolated_call as note if
2113+ // fix-it provided in missingGlobalActorOnContext
21132114 ctx.Diags .diagnose (error.loc , error.diag )
21142115 .limitBehavior (behavior);
21152116 }
@@ -3253,23 +3254,33 @@ namespace {
32533254 if (requiresAsync && !getDeclContext ()->isAsyncContext ()) {
32543255
32553256 if (ctx.LangOpts .hasFeature (Feature::GroupActorErrors)) {
3256- IsolationError isoMismatch =
3257- IsolationError (
3258- apply->getLoc (),
3259- Diagnostic (diag::actor_isolated_call_decl,
3260- *unsatisfiedIsolation,
3261- calleeDecl,
3262- getContextIsolation ()));
3263-
3264- auto iter = applyErrors.find (std::make_pair (*unsatisfiedIsolation, getContextIsolation ()));
3265- if (iter != applyErrors.end ()){
3266- iter->second .push_back (isoMismatch);
3257+
3258+ IsolationError mismatch ([calleeDecl, apply, unsatisfiedIsolation, getContextIsolation]() {
3259+ if (calleeDecl) {
3260+ return IsolationError (
3261+ apply->getLoc (),
3262+ Diagnostic (diag::actor_isolated_call_decl,
3263+ *unsatisfiedIsolation,
3264+ calleeDecl,
3265+ getContextIsolation ()));
32673266 } else {
3268- DiagnosticList list;
3269- list.push_back (isoMismatch);
3270- auto keyPair = std::make_pair (*unsatisfiedIsolation, getContextIsolation ());
3271- applyErrors.insert (std::make_pair (keyPair, list));
3267+ return IsolationError (
3268+ apply->getLoc (),
3269+ Diagnostic (diag::actor_isolated_call,
3270+ *unsatisfiedIsolation,
3271+ getContextIsolation ()));
32723272 }
3273+ }());
3274+
3275+ auto iter = applyErrors.find (std::make_pair (*unsatisfiedIsolation, getContextIsolation ()));
3276+ if (iter != applyErrors.end ()){
3277+ iter->second .push_back ((mismatch));
3278+ } else {
3279+ DiagnosticList list;
3280+ list.push_back ((mismatch));
3281+ auto keyPair = std::make_pair (*unsatisfiedIsolation, getContextIsolation ());
3282+ applyErrors.insert (std::make_pair (keyPair, list));
3283+ }
32733284 } else {
32743285 if (calleeDecl) {
32753286 auto preconcurrency = getContextIsolation ().preconcurrency () ||
@@ -3291,7 +3302,7 @@ namespace {
32913302 if (unsatisfiedIsolation->isGlobalActor ()) {
32923303 missingGlobalActorOnContext (
32933304 const_cast <DeclContext *>(getDeclContext ()),
3294- unsatisfiedIsolation->getGlobalActor ());
3305+ unsatisfiedIsolation->getGlobalActor (), DiagnosticBehavior::Note );
32953306 }
32963307 }
32973308
@@ -3663,18 +3674,18 @@ namespace {
36633674 result.options .contains (ActorReferenceResult::Flags::Preconcurrency);
36643675
36653676 if (ctx.LangOpts .hasFeature (Feature::GroupActorErrors)) {
3666- IsolationError isoMismatch = IsolationError (loc, Diagnostic (diag::actor_isolated_non_self_reference,
3677+ IsolationError mismatch = IsolationError (loc, Diagnostic (diag::actor_isolated_non_self_reference,
36673678 decl,
36683679 useKind,
36693680 refKind + 1 , refGlobalActor,
36703681 result.isolation ));
36713682
36723683 auto iter = refErrors.find (std::make_pair (refKind,result.isolation ));
36733684 if (iter != refErrors.end ()){
3674- iter->second .push_back (isoMismatch );
3685+ iter->second .push_back (mismatch );
36753686 } else {
36763687 DiagnosticList list;
3677- list.push_back (isoMismatch );
3688+ list.push_back (mismatch );
36783689 auto keyPair = std::make_pair (refKind,result.isolation );
36793690 refErrors.insert (std::make_pair (keyPair, list));
36803691 }
@@ -3691,7 +3702,7 @@ namespace {
36913702 if (result.isolation .isGlobalActor ()) {
36923703 missingGlobalActorOnContext (
36933704 const_cast <DeclContext *>(getDeclContext ()),
3694- result.isolation .getGlobalActor ());
3705+ result.isolation .getGlobalActor (), DiagnosticBehavior::Note );
36953706 }
36963707 }
36973708 return true ;
0 commit comments