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

Brent Royal-Gordon brent at architechies.com
Tue Jan 9 23:39:44 CST 2018



> On Jan 9, 2018, at 4:46 PM, Jordan Rose via swift-evolution <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
	}
	…

> 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/20180109/463bd3c8/attachment.html>


More information about the swift-evolution mailing list