|
1 | | -// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete %s -emit-sil -o /dev/null -verify -verify-additional-prefix complete- |
2 | | -// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete %s -emit-sil -o /dev/null -verify -enable-experimental-feature RegionBasedIsolation |
| 1 | +// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -enable-experimental-feature OptionalIsolatedParameters %s -emit-sil -o /dev/null -verify -verify-additional-prefix complete- |
| 2 | +// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -enable-experimental-feature OptionalIsolatedParameters %s -emit-sil -o /dev/null -verify -enable-experimental-feature RegionBasedIsolation |
3 | 3 |
|
4 | 4 | // REQUIRES: concurrency |
5 | 5 | // REQUIRES: asserts |
@@ -357,3 +357,41 @@ func isolated_generic_bad_3<T: AnyActor>(_ t: isolated T) {} |
357 | 357 | // expected-error@-1 {{'isolated' parameter 'T' must conform to 'Actor' or 'DistributedActor' protocol}} |
358 | 358 |
|
359 | 359 | func isolated_generic_ok_1<T: Actor>(_ t: isolated T) {} |
| 360 | + |
| 361 | +class NotSendable {} // expected-complete-note 5 {{class 'NotSendable' does not conform to the 'Sendable' protocol}} |
| 362 | + |
| 363 | +func optionalIsolated(_ ns: NotSendable, to actor: isolated (any Actor)?) async {} |
| 364 | +func optionalIsolatedSync(_ ns: NotSendable, to actor: isolated (any Actor)?) {} |
| 365 | + |
| 366 | +nonisolated func callFromNonisolated(ns: NotSendable) async { |
| 367 | + await optionalIsolated(ns, to: nil) |
| 368 | + |
| 369 | + optionalIsolatedSync(ns, to: nil) |
| 370 | + |
| 371 | + let myActor = A() |
| 372 | + |
| 373 | + await optionalIsolated(ns, to: myActor) |
| 374 | + // expected-complete-warning@-1 {{passing argument of non-sendable type 'NotSendable' into actor-isolated context may introduce data races}} |
| 375 | + |
| 376 | + optionalIsolatedSync(ns, to: myActor) |
| 377 | + // expected-error@-1 {{expression is 'async' but is not marked with 'await'}} |
| 378 | + // expected-note@-2 {{calls to global function 'optionalIsolatedSync(_:to:)' from outside of its actor context are implicitly asynchronous}} |
| 379 | + // expected-complete-warning@-3 {{passing argument of non-sendable type 'NotSendable' into actor-isolated context may introduce data races}} |
| 380 | +} |
| 381 | + |
| 382 | +@MainActor func callFromMainActor(ns: NotSendable) async { |
| 383 | + await optionalIsolated(ns, to: nil) |
| 384 | + // expected-complete-warning@-1 {{passing argument of non-sendable type 'NotSendable' outside of main actor-isolated context may introduce data races}} |
| 385 | + |
| 386 | + optionalIsolatedSync(ns, to: nil) |
| 387 | + |
| 388 | + let myActor = A() |
| 389 | + |
| 390 | + await optionalIsolated(ns, to: myActor) |
| 391 | + // expected-complete-warning@-1 {{passing argument of non-sendable type 'NotSendable' into actor-isolated context may introduce data races}} |
| 392 | + |
| 393 | + optionalIsolatedSync(ns, to: myActor) |
| 394 | + // expected-error@-1 {{expression is 'async' but is not marked with 'await'}} |
| 395 | + // expected-note@-2 {{calls to global function 'optionalIsolatedSync(_:to:)' from outside of its actor context are implicitly asynchronous}} |
| 396 | + // expected-complete-warning@-3 {{passing argument of non-sendable type 'NotSendable' into actor-isolated context may introduce data races}} |
| 397 | +} |
0 commit comments