Skip to content

Extra error messages when compiling switch_expression_using_statement_syntax_error_test.dart for web #51943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stereotype441 opened this issue Apr 4, 2023 · 1 comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.

Comments

@stereotype441
Copy link
Member

In https://dart-review.googlesource.com/c/sdk/+/293200 (Patterns parsing: recover when switch statement syntax used for switch expressions.), I've added a test tests/language/patterns/switch_expression_using_statement_syntax_error_test.dart to verify that error recovery does a good job of handling incorrect switch expression syntax.

When I ran pkg/test_runner/tool/update_static_error_tests.dart to automatically update the error expectations for that test, I was surprised to see some errors that are particular to the web platform:

f(x) => switch (x) {
//              ^
// [web] The type 'dynamic' is not exhaustively matched by the switch cases since it doesn't match 'Object()'.
  case 1: 'one';
  case 2: 'two';
  default: 'three';
  //     ^
  // [web] This couldn't be parsed.
};

main() {}

(I've left out the analyzer and cfe error expectations for brevity).

I'm not sure why the web platform is getting these extra errors, however after some manual experimenting, I'm guessing it may have something to do with the fact that my error recovery technique creates a wildcard pattern whose name token is default. I wonder if for some reason the web compiler gets confused by this, though it seems strange because the name token shouldn't have any effect on semantics.

@stereotype441 stereotype441 added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Apr 4, 2023
@stereotype441
Copy link
Member Author

Never mind, this was user error on my part. I had not rebuilt dart2js recently, so it was manifesting bugs that have since been fixed.

copybara-service bot pushed a commit that referenced this issue Apr 4, 2023
…h expressions.

This change ensure that if the user makes an erroneous switch
expression by imitating the syntax of case statements (i.e. using
`case`, `default`, `:` instead of `=>`, or `;` instead of `,`), error
recovery will understand the user's intent, avoiding follow-on errors.

Fixes #51886.

Bug: #51886, #51943
Change-Id: Icd405d4fd4ddfb1aadcf0867e5a51ba898d4cdbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293200
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
Projects
None yet
Development

No branches or pull requests

1 participant