|
15 | 15 | ////////////////////////
|
16 | 16 |
|
17 | 17 | /// Classes are always non-sendable, so this is non-sendable
|
18 |
| -class NonSendableKlass { // expected-complete-note 25{{}} |
| 18 | +class NonSendableKlass { // expected-complete-note 31{{}} |
| 19 | + // expected-tns-note @-1 {{}} |
19 | 20 | var field: NonSendableKlass? = nil
|
20 | 21 |
|
21 | 22 | func asyncCall() async {}
|
@@ -50,11 +51,17 @@ struct SingleFieldKlassBox { // expected-complete-note 2{{consider making struct
|
50 | 51 | var k = NonSendableKlass()
|
51 | 52 | }
|
52 | 53 |
|
53 |
| -struct TwoFieldKlassBox { |
| 54 | +struct TwoFieldKlassBox { // expected-note {{}} |
54 | 55 | var k1 = NonSendableKlass()
|
55 | 56 | var k2 = NonSendableKlass()
|
56 | 57 | }
|
57 | 58 |
|
| 59 | +class TwoFieldKlassClassBox { |
| 60 | + var k1 = NonSendableKlass() |
| 61 | + var k2 = NonSendableKlass() |
| 62 | + var recursive: TwoFieldKlassClassBox? = nil |
| 63 | +} |
| 64 | + |
58 | 65 | ////////////////////////////
|
59 | 66 | // MARK: Actor Self Tests //
|
60 | 67 | ////////////////////////////
|
@@ -1266,3 +1273,53 @@ func controlFlowTest2() async {
|
1266 | 1273 |
|
1267 | 1274 | useValue(x) // expected-tns-note {{access here could race}}
|
1268 | 1275 | }
|
| 1276 | + |
| 1277 | +//////////////////////// |
| 1278 | +// MARK: Actor Setter // |
| 1279 | +//////////////////////// |
| 1280 | + |
| 1281 | +final actor ActorWithSetter { |
| 1282 | + var field = NonSendableKlass() |
| 1283 | + var twoFieldBox = TwoFieldKlassBox() |
| 1284 | + var twoFieldBoxInTuple = (NonSendableKlass(), TwoFieldKlassBox()) |
| 1285 | + var recursive: ActorWithSetter? = nil |
| 1286 | + var classBox = TwoFieldKlassClassBox() |
| 1287 | + |
| 1288 | + func test1() async { |
| 1289 | + let x = NonSendableKlass() |
| 1290 | + self.field = x |
| 1291 | + await transferToMain(x) // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}} |
| 1292 | + // expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}} |
| 1293 | + } |
| 1294 | + |
| 1295 | + func test2() async { |
| 1296 | + let x = NonSendableKlass() |
| 1297 | + self.twoFieldBox.k1 = x |
| 1298 | + await transferToMain(x) // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}} |
| 1299 | + // expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}} |
| 1300 | + } |
| 1301 | + |
| 1302 | + func test3() async { |
| 1303 | + let x = NonSendableKlass() |
| 1304 | + self.twoFieldBoxInTuple.1.k1 = x |
| 1305 | + await transferToMain(x) // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}} |
| 1306 | + // expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}} |
| 1307 | + } |
| 1308 | + |
| 1309 | + func recursive() async { |
| 1310 | + let x = NonSendableKlass() |
| 1311 | + await self.recursive!.twoFieldBoxInTuple.1.k2 = x |
| 1312 | + // expected-warning @-1 {{non-sendable type '(NonSendableKlass, TwoFieldKlassBox)' in implicitly asynchronous access to actor-isolated property 'twoFieldBoxInTuple' cannot cross actor boundary}} |
| 1313 | + // expected-warning @-2 {{non-sendable type '(NonSendableKlass, TwoFieldKlassBox)' in implicitly asynchronous access to actor-isolated property 'twoFieldBoxInTuple' cannot cross actor boundary}} |
| 1314 | + |
| 1315 | + await transferToMain(x) // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}} |
| 1316 | + // expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}} |
| 1317 | + } |
| 1318 | + |
| 1319 | + func classBox() async { |
| 1320 | + let x = NonSendableKlass() |
| 1321 | + self.classBox.k1 = x |
| 1322 | + await transferToMain(x) // expected-tns-warning {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}} |
| 1323 | + // expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}} |
| 1324 | + } |
| 1325 | +} |
0 commit comments