Skip to content

Improve message when using Dart 3.0 features w/o Dart 3.0 enabled #52324

Open
@pq

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

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-language-patternsIssues with analyzer's support for the patterns language featureanalyzer-uxanalyzer-warningIssues with the analyzer's Warning codesarea-fe-analyzer-sharedAssigned by engineers; when triaging, prefer either area-front-end or area-analyzer.fe-analyzer-shared-parser-recoveryIssues with the shared parser's handling of incorrect codetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions