[swift-evolution] Require parameter names for ENUM Associated Types?

Adrian Zubarev adrian.zubarev at devandartist.com
Tue Nov 29 09:54:33 CST 2016


However there is a problem with pattern matching:

if case .b = myEnumValue { … }
Today we can ignore all the associated values of an enum case in pattern matching.



-- 
Adrian Zubarev
Sent with Airmail

Am 29. November 2016 um 16:52:18, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

I just showed a direction of what could be possible.

Personally I think it would be enough if we had this:

enum MyEnum {
      
    case a
    case b(Int)
    case b(Int, string: String)
}   
Where .b can be overloaded by it’s associated types.



-- 
Adrian Zubarev
Sent with Airmail

Am 29. November 2016 um 16:48:34, Karl (razielim at gmail.com) schrieb:


On 29 Nov 2016, at 14:55, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:

I’d rather would have the ability of overloading enum cases:

enum MyEnum {
       
    case a
    case a(Int)
    case a(label: Int)
    case a(Double)
}
I don’t know how enums work internally, but I spotted a bug recently where the compiler does not allow to declare a function with the same name as an enum case.

SR–3256

I think this is a side effect of this proposal https://github.com/apple/swift-evolution/blob/master/proposals/0036-enum-dot.md



eek… I really would not like that at all.

if case .a(let value) = myEnumValue {
    // what is type(of: value)?
}

- Karl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161129/61b3eb2e/attachment.html>


More information about the swift-evolution mailing list