> On 23 Mar 2018, at 20:51, Guy Steele <guy.ste...@oracle.com> wrote: > > > String s = switch (e) { > case 0 -> break “foofoo”; > case 1: > if (p == 0) break x; > else { String z = hairy(x); break z+z; } > case 2 -> “barbar”; > }; > > Now I decide that case 1 has three subcases. So I change the `if` to a > statement `switch`. > > String s = switch (e) { > case 0 -> break “foofoo”; > case 1: > switch (p) { > case 0: break x; > case 1: break x+x; > default: String z = hairy(x); break z+z; > } > case 2 -> “barbar”; > }; > > FAIL.
The inner switch is actually an expression switch, so you just need an extra break: String s = switch (e) { case 0 -> “foofoo”; case 1: break switch (p) { case 0: break x; case 1: break x+x; default: String z = hairy(x); break z+z; }; case 2 -> “barbar”; }; > All I’m doing is demonstrating that a common refactoring pattern “turn the > `if` statement into a `switch` statement” has more pitfalls than it used to > once we introduce `switch` expressions. Agreed. Gavin