c381425bd3
Expressions can also occur in patterns, either after an equality or relational operator (e.g. `== e`), or after `const` (though what's allowed after `const` is heavily restricted). We need to make sure that the expression parser doesn't greedily treat `=>` as introducing a function expression when parsing these constructs inside a switch expression. But it's ok to allow function expressions inside list patterns, map patterns, parenthesized patterns, and in the argument part of object patterns. (These will be rejected by a later stage of analysis because expressions inside of patterns must be const, and a function expression can't be const. But the parser should still accept them so that we can give useful error messages). Fixes #50591. Bug: https://github.com/dart-lang/sdk/issues/50591 Change-Id: I828555782f5bc8cb8aae8a3948849b7a75bdec57 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273286 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
6 lines
389 B
Plaintext
6 lines
389 B
Plaintext
f(x) => switch(x) { {'x': _} when () => 0 };
|
|
|
|
|
|
f[StringToken]([BeginToken]x[StringToken])[SimpleToken] =>[SimpleToken] switch[KeywordToken]([BeginToken]x[StringToken])[SimpleToken] {[BeginToken] {[BeginToken]'x'[StringToken]:[SimpleToken] _[StringToken]}[SimpleToken] when[KeywordToken] ([BeginToken])[SimpleToken] =>[SimpleToken] 0[StringToken] }[SimpleToken];[SimpleToken]
|
|
[SimpleToken]
|