mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
48 lines
1.2 KiB
Swift
48 lines
1.2 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
// https://github.com/apple/swift/issues/54705
|
|
|
|
enum Time {
|
|
case milliseconds(Int)
|
|
}
|
|
|
|
struct Scheduled<T> {
|
|
let futureResult: EventLoopFuture<T>
|
|
}
|
|
|
|
struct EventLoopFuture<T> {
|
|
func flatMap<V>(_ body: @escaping (T) -> EventLoopFuture<V>) -> EventLoopFuture<V> {
|
|
fatalError()
|
|
}
|
|
}
|
|
|
|
struct EventLoop {
|
|
func makeSucceededFuture<T>(_ v: T) -> EventLoopFuture<T> {
|
|
fatalError()
|
|
}
|
|
|
|
func scheduleTask<T>(in t: Time, _ body: @escaping () -> T) -> Scheduled<T> {
|
|
fatalError()
|
|
}
|
|
}
|
|
|
|
struct Thing {}
|
|
|
|
func bar(eventLoop: EventLoop, process: @escaping (Thing) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
|
|
func doIt(thingsLeft: ArraySlice<Thing>) -> EventLoopFuture<Void> {
|
|
var thingsLeft = thingsLeft
|
|
guard let first = thingsLeft.popFirst() else {
|
|
return eventLoop.makeSucceededFuture(())
|
|
}
|
|
|
|
return process(first).flatMap { [thingsLeft] in
|
|
return eventLoop.scheduleTask(in: .milliseconds(100)) {
|
|
return doIt(thingsLeft: thingsLeft)
|
|
// expected-error@-1 {{cannot convert value of type 'EventLoopFuture<Void>' to closure result type 'Void'}}
|
|
}.futureResult
|
|
}
|
|
}
|
|
|
|
return doIt(thingsLeft: [][...])
|
|
}
|