File tree Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Expand file tree Collapse file tree 4 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -6968,13 +6968,16 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
6968
6968
6969
6969
// 'nonisolated' without '(unsafe)' is not allowed on non-Sendable variables.
6970
6970
auto type = var->getTypeInContext ();
6971
- if (!attr->isUnsafe () && !type->hasError () &&
6972
- !type->isSendableType ()) {
6973
- Ctx.Diags .diagnose (attr->getLocation (),
6974
- diag::nonisolated_non_sendable,
6975
- type)
6976
- .warnUntilSwiftVersion (6 );
6977
- return ;
6971
+ if (!attr->isUnsafe () && !type->hasError ()) {
6972
+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
6973
+ type,
6974
+ SendableCheckContext (dc),
6975
+ Type (),
6976
+ SourceLoc (),
6977
+ attr->getLocation (),
6978
+ diag::nonisolated_non_sendable);
6979
+ if (diagnosed)
6980
+ return ;
6978
6981
}
6979
6982
6980
6983
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ func testUnsafeSendableInAsync() async {
215
215
// ----------------------------------------------------------------------
216
216
// Sendable restriction on key paths.
217
217
// ----------------------------------------------------------------------
218
- class NC : Hashable { // expected-note 2 {{class 'NC' does not conform to the 'Sendable' protocol}}
218
+ class NC : Hashable { // expected-note 3 {{class 'NC' does not conform to the 'Sendable' protocol}}
219
219
func hash( into: inout Hasher ) { }
220
220
static func == ( _: NC , _: NC ) -> Bool { true }
221
221
}
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ final class TestSendable: Sendable {
23
23
init ( ) { }
24
24
}
25
25
26
- final class TestNonsendable { // expected-note 2 {{class 'TestNonsendable' does not conform to the 'Sendable' protocol}}
26
+ final class TestNonsendable { // expected-note 3 {{class 'TestNonsendable' does not conform to the 'Sendable' protocol}}
27
27
init ( ) { }
28
28
}
29
29
Original file line number Diff line number Diff line change @@ -41,3 +41,13 @@ extension NonStrictClass {
41
41
extension StrictStruct {
42
42
@Sendable func f( ) { } // expected-warning{{instance method of non-Sendable type 'StrictStruct' cannot be marked as '@Sendable'}}
43
43
}
44
+
45
+
46
+ struct HasStatics {
47
+ nonisolated static let ns : NonStrictClass = NonStrictClass ( )
48
+
49
+ nonisolated static let ss : StrictStruct = StrictStruct ( )
50
+ // expected-warning@-1{{'nonisolated' can not be applied to variable with non-'Sendable' type 'StrictStruct'}}
51
+ // expected-warning@-2{{static property 'ss' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
52
+ // expected-note@-3{{isolate 'ss' to a global actor, or conform 'StrictStruct' to 'Sendable'}}
53
+ }
You can’t perform that action at this time.
0 commit comments