[swift-evolution] Handling unknown cases in enums [RE: SE-0192]

Jose Cheyo Jimenez cheyo at masters3d.com
Wed Jan 10 14:03:52 CST 2018


On Tue, Jan 9, 2018 at 10:10 PM, Chris Lattner <clattner at nondot.org> wrote:

> On Jan 9, 2018, at 3:07 PM, Jose Cheyo Jimenez <cheyo at masters3d.com>
> wrote:
> > Hi Chris,
> >
> > This is great. Thanks for spending time on this! I am in favor of `case
> #unknown` to only match unknown cases.
> >
> > 1) Would #uknown be available to RawRepresentable structs?
>
> I haven’t considered this, so I’m not sure how that would work.  I had
> assumed that this would be an enum specific concept.
>
> What do you have in mind?  If your raw representation is itself an enum,
> then of course this would work.
>

I was just curious since a RawRepresentable structs ( and OptionSet ) are
very similar to non exhaustive enums in that they would require handling
unknown cases. Currently RawRepresentable is required to use a default even
if all cases are accounted for.

struct Directions: OptionSet {
    let rawValue: UInt8
    static let up    = Directions(rawValue: 1 << 0)
}

let myDir = Directions.up

switch myDir
{
    case .up : print("matched")
    default: print("default required")
}



> > 2) How is the #uknown pattern accomplished? Are you suggesting to
> capture all the compile time known cases so you can do a diff during
> > runtime? (Sorry this is not obvious to me)
>
> The internals of the compiler would handle this, it is difficult to
> explain unless you know the bowels of silgen and irgen :-)
>
> -Chris
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180110/19425a32/attachment.html>


More information about the swift-evolution mailing list