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) {
6941
6941
if (var->hasStorage ()) {
6942
6942
{
6943
6943
// '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.
6946
6946
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 ;
6953
6951
}
6954
6952
}
6955
6953
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