|
8 | 8 |
|
9 | 9 | @globalActor
|
10 | 10 | actor TestGlobalActor {
|
11 |
| - static var shared = TestGlobalActor() |
| 11 | + static let shared = TestGlobalActor() |
12 | 12 | }
|
13 | 13 |
|
14 | 14 | @TestGlobalActor
|
@@ -72,6 +72,38 @@ struct TestStatics {
|
72 | 72 | public actor TestPublicActor {
|
73 | 73 | nonisolated(unsafe) let immutableNonisolatedUnsafeSendable = TestSendable()
|
74 | 74 | // expected-warning@-1 {{'(unsafe)' is unnecessary for a constant public actor property with 'Sendable' type 'TestSendable', consider removing it}} {{14-22=}}
|
| 75 | + |
| 76 | + // https://github.com/swiftlang/swift/issues/78435 |
| 77 | + static var actorStatic = 0 |
| 78 | + // expected-error@-1 {{static property 'actorStatic' is not concurrency-safe because it is nonisolated global shared mutable state}} |
| 79 | + // expected-note@-2{{convert 'actorStatic' to a 'let' constant to make 'Sendable' shared state immutable}}{{10-13=let}} |
| 80 | + // expected-note@-3{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{3-3=nonisolated(unsafe) }} |
| 81 | + // expected-note@-4{{add '@MainActor' to make static property 'actorStatic' part of global actor 'MainActor'}}{{3-3=@MainActor }} |
| 82 | +} |
| 83 | + |
| 84 | +enum EnumSpace { |
| 85 | + static let enumStaticLet = TestSendable() |
| 86 | + |
| 87 | + static var enumStatic = 0 |
| 88 | + // expected-error@-1 {{static property 'enumStatic' is not concurrency-safe because it is nonisolated global shared mutable state}} |
| 89 | + // expected-note@-2{{convert 'enumStatic' to a 'let' constant to make 'Sendable' shared state immutable}}{{10-13=let}} |
| 90 | + // expected-note@-3{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{3-3=nonisolated(unsafe) }} |
| 91 | + // expected-note@-4{{add '@MainActor' to make static property 'enumStatic' part of global actor 'MainActor'}}{{3-3=@MainActor }} |
| 92 | +} |
| 93 | + |
| 94 | +@TestGlobalActor |
| 95 | +enum IsolatedEnumSpace { |
| 96 | + static let inferredGlobalActorStaticLet = TestSendable() |
| 97 | + |
| 98 | + static var inferredGlobalActorStatic = 0 |
| 99 | +} |
| 100 | + |
| 101 | +public actor GlobalActorComputed: GlobalActor { |
| 102 | + static let storage = GlobalActorComputed() |
| 103 | + |
| 104 | + public static var shared: GlobalActorComputed { |
| 105 | + Self.storage |
| 106 | + } |
75 | 107 | }
|
76 | 108 |
|
77 | 109 | @TestGlobalActor
|
|
0 commit comments