Skip to content

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

Open
@pq

Description

@pq

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

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-uxdevexp-warningIssues with the analyzer's Warning codesmodel-error-recoveryError recovery in analyzer/CFE.type-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