[swift-evolution] Proposal: Remove the "fallthrough" keyword

Joe Groff jgroff at apple.com
Mon Dec 7 10:52:28 CST 2015


> On Dec 6, 2015, at 2:48 PM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
> 
> reswitch looks really confusing. Certainly significantly more confusing
> than fallthrough.
> 
> I notice that all the examples here are using relatively trivial cases,
> like `case .LOAD`. Sure it doesn't look confusing there. But it will 
> get confusing with complicated cases:
> 
> switch value {
> case .Foo(bar, .Baz(.Qux(quux), .Corge), .Grault(.Garply)):
>    // do some stuff
>    reswitch(.Foo(bar, .Baz(.Qux(quux), .Corge), .Grault(.Waldo)))
> case .Foo(bar, .Baz(.Qux(quux), .Corge), .Grault(.Waldo)):
>    // do some more stuff
>    // ...
> }
> 
> It also fails to account for those cases where you explicitly cannot
> re-evaluate against the start of the case list because that won't match
> the right case. Trivial example:
> 
> switch value {
> case .Foo(let s) where seen[s] == nil:
>    seen[s] = true
>    fallthrough
> case .Foo:
>    // ...
> }
> 
> There's no way to use reswitch here to bypass that first case (any value
> you might come up with may still pass that where clause and execute the
> first case).

This could also be handled by introducing another state into the 'switch' that shares the destination branch with .Foo.

-Joe


More information about the swift-evolution mailing list