Improve message when using Dart 3.0 features w/o Dart 3.0 enabled #52324
Open
Description
In a project with 2.19 as an SDK upper bound, code that tries to use Dart 3.0 features like this:
class C {
bool isString(Object o) {
return switch (o) {
String() => true,
_ => false,
};
}
}
Produces the following diagnostics:
error: Expected an identifier. (missing_identifier at [analyzer] lib/src/error/use_result_verifier.dart:250)
error: Expected to find ';'. (expected_token at [analyzer] lib/src/error/use_result_verifier.dart:250)
error: A value of type 'dynamic' can't be returned from the method 'isString' because it has a return type of 'bool'. (return_of_invalid_type at [analyzer] lib/src/error/use_result_verifier.dart:250)
error: Expected to find 'case'. (expected_token at [analyzer] lib/src/error/use_result_verifier.dart:251)
I expect what folks really want to see is one message like:
Oh hi, it looks like you're trying to use Dart 3.0 but don't have it enabled. Try bumping your SDK lower bound and you'll be good to go!
(Obviously it should be better but this is the idea.)
Metadata
Assignees
Labels
A bug or feature request we're likely to work onIssues with analyzer's support for the patterns language featureIssues with the analyzer's Warning codesAssigned by engineers; when triaging, prefer either area-front-end or area-analyzer.Issues with the shared parser's handling of incorrect codeA request for a change that isn't a bug