[swift-evolution] if case 1, 2, 3 = x { ... } results in error in swift 2
Kevin Ballard
kevin at sb.org
Thu Dec 3 18:51:35 CST 2015
`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.
`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
More information about the swift-evolution
mailing list