[swift-evolution] Pitch: disallow `()` from Switch statement case satisfaction

Robert Widmann devteam.codafi at gmail.com
Tue Oct 11 14:41:39 CDT 2016


I agree, though it may seem counterintuitive at first.  () is a value of unit type that exists here to satisfy the sema’s requirements that all branches are destructive, productive or defer to another productive branch.

~Robert Widmann

> On Oct 11, 2016, at 2:54 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Well, unless I'm mistaken, `()` here is a value. I can replace it with `3` and the compiler emits a warning about unused results. I'm guessing that since () is a value of type Void, the warning about unused results isn't triggered.
> While it's true that `Void` causes an error, I can write `Void()` instead and everything compiles just fine, which is what the `()` is doing too. Seems fine to me?
> 
> 
> On Tue, Oct 11, 2016 at 1:43 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> I thought this was long gone but today I found out it is still legal:
> 
> switch i {
> case 4 ... 6: ()
> case 3: print("Here")
> default: break
> }
> 
> Is there a motivating factor for keeping this in the language? The compiler picks up on Void and emits an error. You'd think () would produce the same results but it doesn't.
> 
> -- Erica
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161011/27538a33/attachment.html>


More information about the swift-evolution mailing list