Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %target-swift-frontend %s -typecheck

// https://github.com/apple/swift/issues/66041

protocol Middleware<Input, Output, NextInput, NextOutput> {
associatedtype Input
associatedtype Output
associatedtype NextInput
associatedtype NextOutput
}

protocol Routes<Input, Output> {
associatedtype Input
associatedtype Output
}

extension Routes {
func compose<M>(_ middleware: M) -> any Routes<M.NextInput, M.NextOutput> where
M: Middleware,
M.Input == Input,
M.Output == Output
{
fatalError()
}

func mapInput<NewInput>(
_ transform: @escaping (Input) -> NewInput
) -> any Routes<NewInput, Output> {
fatalError()
}
}

struct Request {}
struct Response {}
struct User {}

struct AuthMiddleware<Input, Output>: Middleware {
typealias NextInput = (Input, login: User)
typealias NextOutput = Output
}

func main(routes: any Routes<Request, Response>) {
let routes = routes.compose(AuthMiddleware())
.mapInput {
(request: $0.0, login: $0.login)
}
}