|
5 | 5 | func doAsynchronously() async { } |
6 | 6 | func doSynchronously() { } |
7 | 7 |
|
8 | | -func testNonConversions() async { |
9 | | - let _: () -> Void = doAsynchronously // expected-error{{cannot convert value of type '() async -> ()' to specified type '() -> Void'}} |
10 | | - let _: () async -> Void = doSynchronously // expected-error{{cannot convert value of type '() -> ()' to specified type '() async -> Void'}} |
| 8 | +func testConversions() async { |
| 9 | + let _: () -> Void = doAsynchronously // expected-error{{invalid conversion from 'async' function of type '() async -> ()' to synchronous function type '() -> Void'}} |
| 10 | + let _: () async -> Void = doSynchronously // okay |
11 | 11 | } |
12 | 12 |
|
13 | 13 | // Overloading |
@@ -94,3 +94,24 @@ func testPassAsyncClosure() { |
94 | 94 | let b = takesAsyncClosure { overloadedSame() } // expected-warning{{synchronous is no fun}} |
95 | 95 | let _: Double = b // expected-error{{convert value of type 'String'}} |
96 | 96 | } |
| 97 | + |
| 98 | +struct FunctionTypes { |
| 99 | + var syncNonThrowing: () -> Void |
| 100 | + var syncThrowing: () throws -> Void |
| 101 | + var asyncNonThrowing: () async -> Void |
| 102 | + var asyncThrowing: () async throws -> Void |
| 103 | + |
| 104 | + mutating func demonstrateConversions() { |
| 105 | + // Okay to add 'async' and/or 'throws' |
| 106 | + asyncNonThrowing = syncNonThrowing |
| 107 | + asyncThrowing = syncThrowing |
| 108 | + syncThrowing = syncNonThrowing |
| 109 | + asyncThrowing = asyncNonThrowing |
| 110 | + |
| 111 | + // Error to remove 'async' or 'throws' |
| 112 | + syncNonThrowing = asyncNonThrowing // expected-error{{invalid conversion}} |
| 113 | + syncThrowing = asyncThrowing // expected-error{{invalid conversion}} |
| 114 | + syncNonThrowing = syncThrowing // expected-error{{invalid conversion}} |
| 115 | + asyncNonThrowing = syncThrowing // expected-error{{invalid conversion}} |
| 116 | + } |
| 117 | +} |
0 commit comments