[swift-evolution] Handling unknown cases in enums [RE: SE-0192]
Jordan Rose
jordan_rose at apple.com
Wed Jan 10 12:08:33 CST 2018
> On Jan 9, 2018, at 21:39, Brent Royal-Gordon <brent at architechies.com> wrote:
>
>
>
>> On Jan 9, 2018, at 4:46 PM, Jordan Rose via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>
>> - FWIW I can't actually think of a use case for using this with `if case` or anything else. I'm not against it, but I don't know why you would ever do it, just like I don't know why you would mix `case #unknown` with `default` when matching against a single value.
>
> if case #unknown = someEnum {
> throw MyError.unknownValue
> }
> …
Yes, you can write that, but why would you do it? What are you going to do below now that you know 'someEnum' is a known value but the compiler doesn't?
(Also, it doesn't play well with recompiling…)
>
>> That said, it sounds like people are happier with `case #unknown` than `unknown case`, and that leaves things a little more consistent if we ever do expand it to other pattern positions, so I'll change the proposal revision to use that spelling. (And if anyone comes up with a nicer spelling, great!)
>
> I don't love the spelling of `#unknown`—particularly since some enums in the Apple frameworks actually *have* an ordinary case called "unknown"—but I think it's a nice, pragmatic solution which slots into pattern matching very nicely.
>
> (And if we ever *do* decide to support @testable enum parameters, we'll already have the syntax to specify unknown values.)
>
> --
> Brent Royal-Gordon
> Architechies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180110/1fa77bb6/attachment.html>
More information about the swift-evolution
mailing list