@@ -2033,11 +2033,11 @@ namespace {
2033
2033
2034
2034
// / Note when the enclosing context could be put on a global actor.
2035
2035
// FIXME: This should handle closures too.
2036
- static bool missingGlobalActorOnContext (DeclContext *dc, Type globalActor) {
2036
+ static bool missingGlobalActorOnContext (DeclContext *dc, Type globalActor, DiagnosticBehavior behavior ) {
2037
2037
// If we are in a synchronous function on the global actor,
2038
2038
// suggest annotating with the global actor itself.
2039
2039
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
2041
2041
// actor isolation of an individual accessor. Arguably we could
2042
2042
// add this to the entire storage declaration, though.
2043
2043
// Suppress this for async functions out of caution; but don't
@@ -2056,6 +2056,7 @@ namespace {
2056
2056
fn->diagnose (diag::add_globalactor_to_function,
2057
2057
globalActor->getWithoutParens ().getString (),
2058
2058
fn, globalActor)
2059
+ .limitBehavior (behavior)
2059
2060
.fixItInsert (fn->getAttributeInsertionLoc (false ),
2060
2061
diag::insert_globalactor_attr, globalActor);
2061
2062
return true ;
@@ -2079,14 +2080,14 @@ namespace {
2079
2080
// Add Fix-it for missing @SomeActor annotation
2080
2081
if (isolation.isGlobalActor ()) {
2081
2082
if (missingGlobalActorOnContext (
2082
- const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor ())) {
2083
+ const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor (), behavior )) {
2083
2084
behavior= DiagnosticBehavior::Note;
2084
2085
}
2085
2086
}
2086
2087
2087
2088
for (IsolationError error : errors) {
2088
2089
// Diagnose actor_isolated_non_self_reference as note
2089
- // if we provide fix-it in missingGlobalActorOnContext
2090
+ // if fix-it provided in missingGlobalActorOnContext
2090
2091
ctx.Diags .diagnose (error.loc , error.diag )
2091
2092
.limitBehavior (behavior);
2092
2093
}
@@ -2102,14 +2103,14 @@ namespace {
2102
2103
// Add Fix-it for missing @SomeActor annotation
2103
2104
if (isolation.isGlobalActor ()) {
2104
2105
if (missingGlobalActorOnContext (
2105
- const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor ())) {
2106
+ const_cast <DeclContext*>(getDeclContext ()), isolation.getGlobalActor (), behavior )) {
2106
2107
behavior= DiagnosticBehavior::Note;
2107
2108
}
2108
2109
}
2109
2110
2110
2111
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
2113
2114
ctx.Diags .diagnose (error.loc , error.diag )
2114
2115
.limitBehavior (behavior);
2115
2116
}
@@ -3253,23 +3254,33 @@ namespace {
3253
3254
if (requiresAsync && !getDeclContext ()->isAsyncContext ()) {
3254
3255
3255
3256
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 ()));
3267
3266
} 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 ()));
3272
3272
}
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
+ }
3273
3284
} else {
3274
3285
if (calleeDecl) {
3275
3286
auto preconcurrency = getContextIsolation ().preconcurrency () ||
@@ -3291,7 +3302,7 @@ namespace {
3291
3302
if (unsatisfiedIsolation->isGlobalActor ()) {
3292
3303
missingGlobalActorOnContext (
3293
3304
const_cast <DeclContext *>(getDeclContext ()),
3294
- unsatisfiedIsolation->getGlobalActor ());
3305
+ unsatisfiedIsolation->getGlobalActor (), DiagnosticBehavior::Note );
3295
3306
}
3296
3307
}
3297
3308
@@ -3663,18 +3674,18 @@ namespace {
3663
3674
result.options .contains (ActorReferenceResult::Flags::Preconcurrency);
3664
3675
3665
3676
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,
3667
3678
decl,
3668
3679
useKind,
3669
3680
refKind + 1 , refGlobalActor,
3670
3681
result.isolation ));
3671
3682
3672
3683
auto iter = refErrors.find (std::make_pair (refKind,result.isolation ));
3673
3684
if (iter != refErrors.end ()){
3674
- iter->second .push_back (isoMismatch );
3685
+ iter->second .push_back (mismatch );
3675
3686
} else {
3676
3687
DiagnosticList list;
3677
- list.push_back (isoMismatch );
3688
+ list.push_back (mismatch );
3678
3689
auto keyPair = std::make_pair (refKind,result.isolation );
3679
3690
refErrors.insert (std::make_pair (keyPair, list));
3680
3691
}
@@ -3691,7 +3702,7 @@ namespace {
3691
3702
if (result.isolation .isGlobalActor ()) {
3692
3703
missingGlobalActorOnContext (
3693
3704
const_cast <DeclContext *>(getDeclContext ()),
3694
- result.isolation .getGlobalActor ());
3705
+ result.isolation .getGlobalActor (), DiagnosticBehavior::Note );
3695
3706
}
3696
3707
}
3697
3708
return true ;
0 commit comments