Skip to content

Commit 6e24564

Browse files
committed
[Tests] NFC: Add a test-case for main-actor isolated struct and nonisolated protocol
(cherry picked from commit 82497af)
1 parent a0b0a07 commit 6e24564

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/Concurrency/nonisolated_rules.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ nonisolated struct S1: GloballyIsolated {
102102
nonisolated protocol Refined: GloballyIsolated {}
103103
nonisolated protocol WhyNot {}
104104

105+
nonisolated protocol NonisolatedWithMembers {
106+
func test()
107+
}
108+
105109
struct A: Refined {
106110
var x: NonSendable
107111
init(x: NonSendable) {
@@ -171,6 +175,16 @@ struct NonisolatedStruct {
171175
}
172176
}
173177

178+
@MainActor
179+
struct TestIsolated : NonisolatedWithMembers {
180+
var x: NonSendable // expected-note {{property declared here}}
181+
182+
// requirement behaves as if it's explicitly `nonisolated` which gets inferred onto the witness
183+
func test() {
184+
_ = x // expected-error {{main actor-isolated property 'x' can not be referenced from a nonisolated context}}
185+
}
186+
}
187+
174188
// MARK: - Extensions
175189

176190
nonisolated extension GloballyIsolated {

0 commit comments

Comments
 (0)