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 @@ -6948,13 +6948,16 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
6948
6948
6949
6949
// 'nonisolated' without '(unsafe)' is not allowed on non-Sendable variables.
6950
6950
auto type = var->getTypeInContext ();
6951
- if (!attr->isUnsafe () && !type->hasError () &&
6952
- !type->isSendableType ()) {
6953
- Ctx.Diags .diagnose (attr->getLocation (),
6954
- diag::nonisolated_non_sendable,
6955
- type)
6956
- .warnUntilSwiftVersion (6 );
6957
- return ;
6951
+ if (!attr->isUnsafe () && !type->hasError ()) {
6952
+ bool diagnosed = diagnoseIfAnyNonSendableTypes (
6953
+ type,
6954
+ SendableCheckContext (dc),
6955
+ Type (),
6956
+ SourceLoc (),
6957
+ attr->getLocation (),
6958
+ diag::nonisolated_non_sendable);
6959
+ if (diagnosed)
6960
+ return ;
6958
6961
}
6959
6962
6960
6963
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