Pattern switch in Dart not supported

Hello!
To resolve “Scrabble score” problem, I wrote :

int score(String word) {
  String s = word.toUpperCase();
  int total = 0;
  for (int i = 0; i < s.length; i++) {
    int add = switch (s[i]) {
      'A' || 'E' || 'I' || 'O' || 'U' || 'L' || 'N' || 'R' || 'S' || 'T' => 1,
      'D' || 'G' => 2,
      'B' || 'C' || 'M' || 'P' => 3,
      'F' || 'H' || 'V' || 'W' || 'Y' => 4,
      'K' => 5,
      'J' || 'X' => 8,
      'Q' || 'Z' => 10,
      _ => 0,
    };
    total += add;
  }
  return total;
}

This code works well inDartPad but does not pass the tests here :

loading test/scrabble_score_test.dart [E] Failed to load “test/scrabble_score_test.dart”: lib/scrabble_score.dart:Expected an identifier, but got ‘switch’. Try inserting an identifier before ‘switch’.

It seems that the Dart version used in Exercism does not match the latest version of Dart. Can anyone confirm ?

dart-test-runner/Dockerfile at main · exercism/dart-test-runner · GitHub shows Dart 2.18

Ok, thank you :slightly_smiling_face:
The latest version of Dart is 3.3
The switch expressions have appeared in version 3.0 :
https://dart.dev/guides/language/evolution

We’re waiting on these PRs to be approved and merged.

1 Like

Are you waiting on me or Erik for this, or a contributor?

@vaeng it looks like these are OK to merge. Who gets to pull the trigger?

Sure. I am just your every day normal dart guy and have no rights to trigger anything on that track. :slight_smile:

1 Like

OK, let’s give the job/responsibility/blame (:wink:) to @ErikSchierboom this week :slight_smile:

1 Like

Both merged

2 Likes

And now Dart 3.x solutions can successfully test: For example glennj's solution for Bob in Dart on Exercism

1 Like