// RUN: %target-typecheck-verify-swift // https://github.com/apple/swift/issues/54705 enum Time { case milliseconds(Int) } struct Scheduled { let futureResult: EventLoopFuture } struct EventLoopFuture { func flatMap(_ body: @escaping (T) -> EventLoopFuture) -> EventLoopFuture { fatalError() } } struct EventLoop { func makeSucceededFuture(_ v: T) -> EventLoopFuture { fatalError() } func scheduleTask(in t: Time, _ body: @escaping () -> T) -> Scheduled { fatalError() } } struct Thing {} func bar(eventLoop: EventLoop, process: @escaping (Thing) -> EventLoopFuture) -> EventLoopFuture { func doIt(thingsLeft: ArraySlice) -> EventLoopFuture { 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' to closure result type 'Void'}} }.futureResult } } return doIt(thingsLeft: [][...]) }