"fallthrough" + "guard/else"

Can anybody please confirm, that this usage of "fallthrough" is eligible? :pray: (the code compiles)

extension URLRequest {
    init(url: URL, httpMethod: HTTPMethod, token: String? = nil) {
        switch httpMethod {
        case .post(let body), .put(let body?):
            guard let httpBody = try? body.encode() else { fallthrough }
            self.init(url, httpMethod.name, httpBody, "application/json", token)
        default:
            self.init(url, httpMethod.name, nil, nil, token)
        }
    }
}
1 Like

(EDITIED) It looks like the fallthrough here has nothing to do with guard/else here. fallthrough is used to jump to the next case block, and since it jumps out of the current context, guard/else accepts it (just like return in a func).

2 Likes