[swift-evolution] if case 1, 2, 3 = x { ... } results in error in swift 2

Amir Michail a.michail at me.com
Thu Dec 3 18:55:18 CST 2015


> On Dec 3, 2015, at 7:51 PM, Kevin Ballard <kevin at sb.org> wrote:
> 
> `if case 1, 2, 3 = x {` does not work because case statements can only
> contain a single pattern when used in an if/for/while. Only when found
> in `switch` statements can they contain multiple comma-separated
> patterns.

But why aren’t multiple comma-separated patterns supported in if/for/while just like in switch statements?

I think they should be.

> 
> `if case 1...3 = x {` works because this a single pattern `1...3`, and
> it's equivalent to saying `if 1...3 ~= x {` (`~=` is the operator that
> is used for doing value comparisons in patterns, and it's implemented
> for all `IntervalType`s to call `interval.contains(x)`).
> 
> Also, this seems like a question that's more appropriate for swift-users
> than swift-evolution.
> 
> On Thu, Dec 3, 2015, at 04:40 PM, Amir Michail wrote:
>> But "if case 1...3 = x { ... }" works.
>> 
>> Why?
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> 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



More information about the swift-evolution mailing list