Skip to content

Commit 82497af

Browse files
committed
[Tests] NFC: Add a test-case for main-actor isolated struct and nonisolated protocol
1 parent 7e42a19 commit 82497af

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
@@ -100,6 +100,10 @@ nonisolated struct S1: GloballyIsolated {
100100
nonisolated protocol Refined: GloballyIsolated {}
101101
nonisolated protocol WhyNot {}
102102

103+
nonisolated protocol NonisolatedWithMembers {
104+
func test()
105+
}
106+
103107
struct A: Refined {
104108
var x: NonSendable
105109
init(x: NonSendable) {
@@ -169,6 +173,16 @@ struct NonisolatedStruct {
169173
}
170174
}
171175

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

174188
nonisolated extension GloballyIsolated {

0 commit comments

Comments
 (0)