Skip to content

Commit f467c0a

Browse files
committed
[Concurrency] Add more tests for async overloading.
1 parent e5d587a commit f467c0a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/Constraints/async.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ func testNonConversions() async {
99
}
1010

1111
// Overloading
12+
@available(swift, deprecated: 4.0, message: "synchronous is no fun")
13+
func overloadedSame() -> String { "synchronous" }
14+
15+
func overloadedSame() async -> String { "asynchronous" }
16+
1217
func overloaded() -> String { "synchronous" }
1318
func overloaded() async -> Double { 3.14159 }
1419

1520
func testOverloadedSync() {
21+
_ = overloadedSame() // expected-warning{{synchronous is no fun}}
22+
1623
let _ = overloaded()
1724
let fn = {
1825
overloaded()
@@ -38,6 +45,8 @@ func testOverloadedSync() {
3845
}
3946

4047
func testOverloadedAsync() async {
48+
_ = await overloadedSame() // no warning
49+
4150
let _ = await overloaded()
4251
let _ = overloaded() // expected-error{{call is 'async' but is not marked with 'await'}}
4352

@@ -63,3 +72,14 @@ func testOverloadedAsync() async {
6372
}
6473
let _: Int = fn4 // expected-error{{value of type '() async -> ()'}}
6574
}
75+
76+
func takesAsyncClosure(_ closure: () async -> String) -> Int { 0 }
77+
func takesAsyncClosure(_ closure: () -> String) -> String { "" }
78+
79+
func testPassAsyncClosure() {
80+
let a = takesAsyncClosure { await overloadedSame() }
81+
let _: Double = a // expected-error{{convert value of type 'Int'}}
82+
83+
let b = takesAsyncClosure { overloadedSame() } // expected-warning{{synchronous is no fun}}
84+
let _: Double = b // expected-error{{convert value of type 'String'}}
85+
}

0 commit comments

Comments
 (0)