Hi,
I found this annoying: Xtend forces type guard of case clause to be compatible with switch variable's type. Shown as follows:
def foo() {
val i = 1
switch i {
List: { // <--- Compile error: Cannot cast from int or Integer to List
}
}
}
And in following case, it even prevents the source file from being saved to disk:
---------------------------------------------------------------------
package foo /* Multiple markers at this line
- UnsupportedOperationException: Missing implementation for int
& List (see logs for details)
- Missing implementation for int & List - See error log for details
- Missing implementation for Formatter & List - See error log
for details
*/
import java.util.List
class Formatter {
override toString() {
val int x = 1
switch x {
List: {
return '''[
«FOR e : x»e«ENDFOR» // <--------------- this line causes errors at 1st line and makes the file unsaveable
]'''
}
}
return ""
}
}
I checked errors/warnings page in xtend compiler settings and didn't find related option.
In first case, it could be interpreted that the var i is Integer type and cannot be a List, so the case typeguarded by List can never be executed. However IMHO, I think this is a too strict limitation to disallow this code, since I know what I'm doing. It's just another kind of dead code, like: if (false) {..}, far from illegal. It would be helpful when writing initial, prototype or not-prefectly-understood code.
So I suggest loosen the limitation, or at least to add a configure option to let programmer decide whether to allow or disallow this kind of code.