|
| 1 | +// RUN: %target-typecheck-verify-swift -enable-experimental-move-only |
| 2 | +// REQUIRES: concurrency |
| 3 | +// REQUIRES: OS=macosx |
| 4 | + |
| 5 | +// rdar://106849189 move-only types should be supported in freestanding mode |
| 6 | +// UNSUPPORTED: freestanding |
| 7 | + |
| 8 | +/// Such a type may be encountered since Swift 5.5 (5.1 backdeployed) if someone implemented the |
| 9 | +/// not documented, but public Executor types back then already. Allow these to be implemented |
| 10 | +/// without warnings. |
| 11 | +@available(SwiftStdlib 5.1, *) |
| 12 | +final class OldExecutorOldStdlib: SerialExecutor { |
| 13 | + func enqueue(_ job: UnownedJob) {} |
| 14 | + |
| 15 | + func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 16 | + UnownedSerialExecutor(ordinary: self) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +/// We warn on the ExecutorJob witness if the type has a broader |
| 21 | +/// availability, since in this case the UnownedJob version needs to exist. |
| 22 | +@available(SwiftStdlib 5.1, *) |
| 23 | +final class BothExecutorOldStdlib: SerialExecutor { |
| 24 | + func enqueue(_ job: UnownedJob) {} |
| 25 | + |
| 26 | + @available(SwiftStdlib 5.9, *) |
| 27 | + func enqueue(_ job: __owned ExecutorJob) {} // expected-warning{{'Executor.enqueue(ExecutorJob)' will never be used, due to the presence of 'enqueue(UnownedJob)'}} |
| 28 | + |
| 29 | + func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 30 | + UnownedSerialExecutor(ordinary: self) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +/// Meanwhile, we warn on the UnownedJob overload if the availability is new enough |
| 35 | +/// that it can be dropped. |
| 36 | +@available(SwiftStdlib 5.9, *) |
| 37 | +final class BothExecutorNewStdlib: SerialExecutor { |
| 38 | + func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'BothExecutorNewStdlib' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}} |
| 39 | + |
| 40 | + func enqueue(_ job: __owned ExecutorJob) {} |
| 41 | + |
| 42 | + func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 43 | + UnownedSerialExecutor(ordinary: self) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +@available(SwiftStdlib 5.9, *) |
| 48 | +final class TripleExecutor: SerialExecutor { |
| 49 | + func enqueue(_ job: UnownedJob) {} // expected-warning{{'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; conform type 'TripleExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}} |
| 50 | + |
| 51 | + // expected-warning@+2{{'Job' is deprecated: renamed to 'ExecutorJob'}} |
| 52 | + // expected-note@+1{{use 'ExecutorJob' instead}} |
| 53 | + func enqueue(_ job: __owned Job) {} // expected-warning{{'Executor.enqueue(Job)' is deprecated as a protocol requirement; conform type 'TripleExecutor' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead}} |
| 54 | + |
| 55 | + func enqueue(_ job: consuming ExecutorJob) {} |
| 56 | + |
| 57 | + func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 58 | + UnownedSerialExecutor(ordinary: self) |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +/// Implementing the new signature on 5.9 platforms is good, no warnings |
| 63 | +@available(SwiftStdlib 5.9, *) |
| 64 | +final class NewExecutorNewStdlib: SerialExecutor { |
| 65 | + func enqueue(_ job: __owned ExecutorJob) {} |
| 66 | + |
| 67 | + func asUnownedSerialExecutor() -> UnownedSerialExecutor { |
| 68 | + UnownedSerialExecutor(ordinary: self) |
| 69 | + } |
| 70 | +} |
0 commit comments