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

Erica Sadun erica at ericasadun.com
Tue Oct 11 15:31:05 CDT 2016


Fair enough. I defer to both of you.

Thanks, -- E

> On Oct 11, 2016, at 1:41 PM, Robert Widmann <devteam.codafi at gmail.com> wrote:
> 
> 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 <mailto: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 <mailto: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/e50f0997/attachment.html>


More information about the swift-evolution mailing list