Just how smart is Swift really when it comes to exhaustive switch clauses?
Disclaimer: this is only semi-serious.
From The Swift Programming Language (Swift 2 Edition):
Every switch statement must be exhaustive. That is, every possible value of the type being considered must be matched by one of the switch cases.
Well Swift let’s see if you really mean it:
I was lied to.
If you want to experiment on your own, here’s the program that writes the program:
Note: I expected to use
UInt8.min...UInt8.max for the range. However that will not work, as explained by Ole Begemann in Ranges and Intervals in Swift.
By the way, I’m curious if anyone else immediately thought about trying this out after learning about
switch in Swift. I can’t be the only one, can I?