Skip to content

Commit 4f24761

Browse files
committed
Suggest global actor isolation rather than 'isolated' for conformances
Update diagnostic and Fix-It to suggest global actor isolation on a conformance (e.g, `@MainActor P`) rather than `isolated`.
1 parent 71a516b commit 4f24761

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8332,8 +8332,8 @@ ERROR(isolated_conformance_mismatch_with_associated_isolation,none,
83328332
"%0 conformance of %1 to %2 cannot depend on %3 conformance of %4 to %5",
83338333
(ActorIsolation, Type, DeclName, ActorIsolation, Type, DeclName))
83348334
NOTE(add_isolated_to_conformance,none,
8335-
"add 'isolated' to the %0 conformance to restrict it to %1 code",
8336-
(DeclName, ActorIsolation))
8335+
"add '%0' to the %1 conformance to restrict it to %2 code",
8336+
(StringRef, DeclName, ActorIsolation))
83378337
ERROR(isolated_conformance_with_sendable,none,
83388338
"isolated conformance of %0 to %1 cannot be used to satisfy conformance "
83398339
"requirement for a %select{`Sendable`|`SendableMetatype`}2 type "

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,17 +3590,22 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
35903590
}
35913591

35923592
// Another way to address the issue is to mark the conformance as
3593-
// "isolated" or "@preconcurrency".
3593+
// isolated to the global actor or "@preconcurrency".
35943594
if (Conformance->getSourceKind() == ConformanceEntryKind::Explicit &&
35953595
!Conformance->isGlobalActorIsolated() &&
35963596
!Conformance->isPreconcurrency() &&
35973597
!suggestedPreconcurrencyOrIsolated &&
3598-
!requirementIsolation.isActorIsolated()) {
3598+
!requirementIsolation.isActorIsolated() &&
3599+
refResult.isolation.isGlobalActor()) {
35993600
if (Context.LangOpts.hasFeature(Feature::IsolatedConformances)) {
3601+
std::string globalActorStr = "@" +
3602+
refResult.isolation.getGlobalActor().getString();
36003603
Context.Diags.diagnose(Conformance->getProtocolNameLoc(),
36013604
diag::add_isolated_to_conformance,
3605+
globalActorStr,
36023606
Proto->getName(), refResult.isolation)
3603-
.fixItInsert(Conformance->getProtocolNameLoc(), "isolated ");
3607+
.fixItInsert(Conformance->getProtocolNameLoc(),
3608+
globalActorStr + " ");
36043609
}
36053610

36063611
Context.Diags.diagnose(Conformance->getProtocolNameLoc(),

test/Concurrency/isolated_conformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protocol P {
1212
// ----------------------------------------------------------------------------
1313

1414
// expected-note@+3{{add '@preconcurrency' to the 'P' conformance to defer isolation checking to run time}}{{25-25=@preconcurrency }}
15-
// expected-note@+2{{add 'isolated' to the 'P' conformance to restrict it to main actor-isolated code}}{{25-25=isolated }}
15+
// expected-note@+2{{add '@MainActor' to the 'P' conformance to restrict it to main actor-isolated code}}{{25-25=@MainActor }}
1616
@MainActor
1717
class CWithNonIsolated: P {
1818
func f() { } // expected-error{{main actor-isolated instance method 'f()' cannot be used to satisfy nonisolated requirement from protocol 'P'}}

0 commit comments

Comments
 (0)