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 @@ -6941,15 +6941,13 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
69416941 if (var->hasStorage ()) {
69426942 {
69436943 // 'nonisolated' can not be applied to mutable stored properties unless
6944- // qualified as 'unsafe', or is of a Sendable type on a
6945- // globally-isolated value type.
6944+ // qualified as 'unsafe', or is of a Sendable type on a Sendable
6945+ // value type.
69466946 bool canBeNonisolated = false ;
6947- if (dc->isTypeContext ()) {
6948- if (auto nominal = dc->getSelfStructDecl ()) {
6949- if (!var->isStatic () && type->isSendableType () &&
6950- getActorIsolation (nominal).isGlobalActor ()) {
6951- canBeNonisolated = true ;
6952- }
6947+ if (auto nominal = dc->getSelfStructDecl ()) {
6948+ if (nominal->getDeclaredTypeInContext ()->isSendableType () &&
6949+ !var->isStatic () && type->isSendableType ()) {
6950+ canBeNonisolated = true ;
69536951 }
69546952 }
69556953
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