D-Programming-Language/dmd — pull request #2905 by 9rnsr (2013-12-01 08:58:24+00:00)
Title: Issue 11653 - No error when forgetting break with range cases

https://d.puremagic.com/issues/show_bug.cgi?id=11653

Currently nested `CompoundStatement` (one of the element of `statements` field may be `CompoundStatement`) is allowed. However, "switch case fallthrough" warning, which is checked in `CompoundStatement::blockExit`, depends on the _completely_ flatten `CompoundStatement`. So, to make the warning check possible, flatten such nested `CompoundStatement` in its `semantic`.

But, just only doing it will break some existing assumptions. To avoid breakage,

1. Use `ScopeStatement` instead of `CompoundStatement` for the goto patch placeholder inside foreach.
To replace goto-statement, which jump out to the foreach block, to the return-statement, CompoundStatement is used as placeholder. But nested CompoundStatement will be removed, so use ScopeStatement instead.

2. If `LabelStatement::flatten` is called after semantic, it will create new LabelStatement and will break internal semantic information (eg. LabelStatement::gotoTarget). To avoid breakage, reuse 'this'.