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) {
7005
7005
if (var->hasStorage ()) {
7006
7006
{
7007
7007
// '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.
7010
7010
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 ;
7017
7015
}
7018
7016
}
7019
7017
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 19
19
@MainActor
20
20
public protocol P { }
21
21
22
+ @frozen
23
+ public struct ImplicitlySendable {
24
+ nonisolated public var prop : Bool = true
25
+
26
+ nonisolated public init ( ) { }
27
+ }
28
+
22
29
public struct S : P {
23
30
nonisolated public var x : Int = 0
24
31
@@ -32,5 +39,7 @@ actor A {
32
39
func test( ) {
33
40
var s = S ( )
34
41
s. x += 0 // okay
42
+ var sendable = ImplicitlySendable ( )
43
+ sendable. prop = false // okay
35
44
}
36
45
}
You can’t perform that action at this time.
0 commit comments