Community
Participate
Working Groups
Created attachment 256278 [details] Generated code Xtend 2.8.4 seems to allow strange switch expressions like the following: def getFoo(Object obj) { switch (obj) { String: "foo", Integer: "bar" : "???" default: "!!!" } } Please notice the comma after "foo" and the colon after "bar". The commas can even be repeated, so this is grammatically correct: def getFoo2(Object obj) { switch (obj) { ,,,,,,: "???" } } Also, this seems to coincidentally allow a nice shorthand: def getBar(Object obj) { switch (obj) { String: "bar" : "???" } } I like the idea of allowing commas for switch case separation, and I can't think of any ambiguities involving fall-through commas. def getBar2(Object obj) { switch (obj) { String: "bar", Integer: "foo", default: "???" } } Which seems to produce code equivalent to: def getBar3(Object obj) { switch (obj) { String: "bar" default: "???" } } I attached the generated code.
Sorry, getBar3() is equivalent to getBar() of course, not to getBar2().
we should invalidate XCasePart without 'typeGuard' or 'case'.
This should do it: XCasePart: {XCasePart} (typeGuard=JvmTypeReference ('case' case=XExpression)? |'case' case=XExpression) (':' then=XExpression | fallThrough?=',') ;