[swift-evolution] "where" on a switch case with multiple items is misleading

Lucas Neiva lucas.neiva at ergon.ch
Fri Mar 11 08:51:42 CST 2016


Requiring “where" for all patterns seems like a good idea. I’ve run into this before.

Instinctively I tried to group using ( ), but then you’re matching tuples:

	case (a, b) where <where-expression>:

Having a way to apply the where-clause to all patterns would be nice. Maybe like this:

	case let a, b where all <where-expression>:

> Consider:
> 
> switch x {
> case a, b where …: ...
> }
> 
> this currently means:
> 
> switch x {
> case a where true, b where …: ...
> }
> 
> Most people would probably think the “where" applies to both a and b.
> 
> To avoid this confusion, maybe if “where" is used for one item then it should be required for all items in that case?
> 
> 
> 
> 


More information about the swift-evolution mailing list