Skip to content

Commit 27b57c6

Browse files
committed
[Concurrency] clarify diagnostic for 'nonisolated' stored properties being due to mutability
1 parent e7475c8 commit 27b57c6

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5655,8 +5655,12 @@ ERROR(nonisolated_let,none,
56555655
"they are immutable",
56565656
())
56575657
ERROR(nonisolated_mutable_storage,none,
5658-
"'nonisolated' can not be applied to stored properties",
5658+
"'nonisolated' cannot be applied to mutable stored properties",
56595659
())
5660+
NOTE(nonisolated_mutable_storage_note,none,
5661+
"convert %0 to a 'let' constant or consider declaring it "
5662+
"'nonisolated(unsafe)' if manually managing concurrency safety",
5663+
(const VarDecl *))
56605664
ERROR(nonisolated_local_var,none,
56615665
"'nonisolated' can not be applied to local variables",
56625666
())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6861,7 +6861,9 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
68616861
// 'nonisolated' can not be applied to mutable stored properties unless
68626862
// qualified as 'unsafe'.
68636863
if (var->supportsMutation() && !attr->isUnsafe()) {
6864-
diagnoseAndRemoveAttr(attr, diag::nonisolated_mutable_storage);
6864+
diagnoseAndRemoveAttr(attr, diag::nonisolated_mutable_storage)
6865+
.fixItInsertAfter(attr->getRange().End, "(unsafe)");
6866+
var->diagnose(diag::nonisolated_mutable_storage_note, var);
68656867
return;
68666868
}
68676869

test/Concurrency/actor_isolation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ struct InferredFromContext {
139139
get { [] }
140140
}
141141

142-
nonisolated var status: Bool = true // expected-error {{'nonisolated' can not be applied to stored properties}}{{3-15=}}
142+
nonisolated var status: Bool = true // expected-error {{'nonisolated' cannot be applied to mutable stored properties}}{{3-15=}}{{3-15=}}{{14-14=(unsafe)}}
143+
// expected-note@-1{{convert 'status' to a 'let' constant or consider declaring it 'nonisolated(unsafe)' if manually managing concurrency safety}}
143144

144145
nonisolated let flag: Bool = false // expected-warning {{'nonisolated' is redundant on struct's stored properties; this is an error in Swift 6}}{{3-15=}}
145146

0 commit comments

Comments
 (0)