Open
Description
Let's take the example from https://dart.dev/language/branches#switch-expressions:
// Where slash, star, comma, semicolon, etc., are constant variables...
token = switch (charCode) {
slash || star || plus || minus => operator(charCode),
comma || semicolon => punctuation(charCode),
>= digit0 && <= digit9 => number(),
_ => throw FormatException('Invalid')
};
It assumes that slash
, star
, ... are constant variables, but how are they defined? I expect to be able to do:
const slash = '/'.codeUnitAt(0); // Error: Methods can't be invoked in constant expressions.
// ...
but I can't, and it's ugly and error-prone to find out what the char code for each of the characters are and put the integer in instead.