-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable] Patterns parser: prohibit variable/identifier patterns named…
… when/as. In https://dart-review.googlesource.com/c/sdk/+/299400, the parser was adjusted so that it no longer accepts `when` and `as` as the names for variable patterns in cases where there is a possible ambiguity (e.g. `int when` is not accepted as a pattern because `int` is a legitimate pattern, therefore `when` could introduce a guard clause). This change further prohibits `when` and `as` from being the names of variable patterns or identifier patterns even in the case where there is no ambiguity. This is in line with the discussion at #52199 (comment), and the spec change at dart-lang/language#3033. Three new error codes are introduced, to cover the three circumstances in which `when` or `as` might be used illegally: in a declared variable pattern, in an assigned variable pattern, or in an identifier pattern. I've also added analyzer tests to ensure that the parser recovers from these errors nicely. Unfortunately, nice error recovery is only feasible in the non-ambiguous cases. I've also updated the language test expectations in `tests/language/patterns/version_2_32_changes_error_test.dart` to reflect the new error messages, and added a few more examples of uses of `when` and `as` that are still permitted. Fixes: #52311 Bug: #52260 Change-Id: I30cb3a1ca627c6db3d281740fb59de74c4118c2b Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/301482 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302100 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
- Loading branch information
1 parent
c6b0b74
commit 2f11564
Showing
38 changed files
with
1,359 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
pkg/front_end/parser_testcases/patterns/assignedVariable_namedAs.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void f(x) { | ||
dynamic as; | ||
(as) = x; | ||
} |
Oops, something went wrong.