How to use pattern match for overloaded enum?

It compiles fine.

enum EnumOverload {
    case value(int: Int)
    case value(string: String)
    case value(bool: Bool)
}

I can use EnumOverload.value(int: 42) and the similar with no problem, but on the pattern match it cannot used.

This is the code Xcode generated for swiftch, but it causes error.

extension EnumOverload: CustomStringConvertible {
    var description: String {
        switch self {
        case .value(int: let int): return "\(int)"
        case .value(string: let string): return "\(string)"
        case .value(bool: let bool): return "\(bool)"
        }
    }
}

As far as I know, there is no way to use label on pattern match. Is it possible to use pattern match for this enum? And if it is impossible, for what this overload is allowed?

It's a known bug. SE-0155, Expired Proposal contained a detailed description of what should've happened in case of same base-name cases,

but due to the new expiration policies and the fact that SE-0155 hasn't been fully implemented in an year from its acceptance, that section has been removed. You can read more in Addressing unimplemented evolution proposals.


Side note: are you able to access bugs.swift.org? For me, the website is unavailable (it's giving me a 503 error since Saturday).

3 Likes

Thank you for reply, I didn't know how that happened. I'll read proposals and threads!


I can't access it either :cry:

As Stefano pointed out, this feature hasn't been fully implemented. I've created [SR-14638] ☂️ Full support for overloaded enum cases (SE-0155) · Issue #56990 · apple/swift · GitHub to collect bugs related to this.

1 Like