File tree Expand file tree Collapse file tree 3 files changed +42
-8
lines changed
Expand file tree Collapse file tree 3 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -7005,15 +7005,13 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
70057005 if (var->hasStorage ()) {
70067006 {
70077007 // 'nonisolated' can not be applied to mutable stored properties unless
7008- // qualified as 'unsafe', or is of a Sendable type on a
7009- // globally-isolated value type.
7008+ // qualified as 'unsafe', or is of a Sendable type on a Sendable
7009+ // value type.
70107010 bool canBeNonisolated = false ;
7011- if (dc->isTypeContext ()) {
7012- if (auto nominal = dc->getSelfStructDecl ()) {
7013- if (!var->isStatic () && type->isSendableType () &&
7014- getActorIsolation (nominal).isGlobalActor ()) {
7015- canBeNonisolated = true ;
7016- }
7011+ if (auto nominal = dc->getSelfStructDecl ()) {
7012+ if (nominal->getDeclaredTypeInContext ()->isSendableType () &&
7013+ !var->isStatic () && type->isSendableType ()) {
7014+ canBeNonisolated = true ;
70177015 }
70187016 }
70197017
Original file line number Diff line number Diff line change 1+ // RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify
2+ // RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -strict-concurrency=complete
3+
4+ // REQUIRES: concurrency
5+ // REQUIRES: asserts
6+
7+ class NonSendable { }
8+
9+ struct ImplicitlySendable {
10+ var x : Int
11+ nonisolated var y : Int // okay
12+ }
13+
14+ struct ImplicitlyNonSendable {
15+ let x : NonSendable
16+ // expected-note@+1 {{convert 'y' to a 'let' constant or consider declaring it 'nonisolated(unsafe)' if manually managing concurrency safety}}
17+ nonisolated var y : Int // expected-error {{'nonisolated' cannot be applied to mutable stored properties}}
18+ }
19+
20+ public struct PublicSendable : Sendable {
21+ nonisolated var x : Int // okay
22+ }
23+
24+ public struct PublicNonSendable {
25+ // expected-note@+1 {{convert 'x' to a 'let' constant or consider declaring it 'nonisolated(unsafe)' if manually managing concurrency safety}}
26+ nonisolated var x : Int // expected-error {{'nonisolated' cannot be applied to mutable stored properties}}
27+ }
Original file line number Diff line number Diff line change 1919@MainActor
2020public protocol P { }
2121
22+ @frozen
23+ public struct ImplicitlySendable {
24+ nonisolated public var prop : Bool = true
25+
26+ nonisolated public init ( ) { }
27+ }
28+
2229public struct S : P {
2330 nonisolated public var x : Int = 0
2431
@@ -32,5 +39,7 @@ actor A {
3239 func test( ) {
3340 var s = S ( )
3441 s. x += 0 // okay
42+ var sendable = ImplicitlySendable ( )
43+ sendable. prop = false // okay
3544 }
3645}
You can’t perform that action at this time.
0 commit comments