I have 2 ideas in my mind:
1) Implement switch expression from scratch, in other words, we need parse code into a brand new`SwitchExpression` in AST, then implement flowing type because we have static groovy, at last generate bytecode. -- need quite a few work, but it should be able to very close to Java's implementation, better compatibility. 2) Transform the switch expression to reuse current AST nodes, as a result, we can reuse almost all backend. -- can not ensure 100% compatibility with Java's switch expression, but need much less work, and the implementation should be robust because it is based on mature backend used for years. We have to trade off pros and crons. For me, I choose the option 2. As for the potential side effect you mentioned, I think we can transform again in a later phase if necessary: The original code: ``` def a = 6 def r = switch (a) { case 6, 8 -> 'x' case 9 -> 'y' default -> 'z' } assert 'x' == r ``` 1st transformed code in the parser: ``` def a = 6 def r = {-> def result = null switch (a) { case 6: case 8: result = 'x'; break; case 9: result = 'y'; break; default: result = 'z'; break; } return result }() assert 'x' == r ``` 2nd transformed code in the parser to eliminate the shared variables before instruction selection phase: ``` def a = 6 def r = { paramA -> def result = null switch (paramA) { case 6: case 8: result = 'x'; break; case 9: result = 'y'; break; default: result = 'z'; break; } return result }(a) assert 'x' == r ``` Cheers, Daniel.Sun ----- Apache Groovy committer & PMC member Blog: http://blog.sunlan.me Twitter: @daniel_sun -- Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html