Files
sdk/pkg/front_end/parser_testcases/patterns/issue50591_example2.dart.parser.expect
Paul Berry c381425bd3 Parser: additional fixes to mayParseFunctionExpressions for patterns.
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>
2022-12-02 15:04:09 +00:00

14 lines
535 B
Plaintext

void f(Object? x) {
(switch (x) {
const A() => 0,
_ => 1,
});
}
[UnmatchedToken]void[KeywordToken] f[StringToken]([BeginToken]Object[StringToken]?[SimpleToken] x[StringToken])[SimpleToken] {[BeginToken]
([BeginToken]switch[KeywordToken] ([BeginToken]x[StringToken])[SimpleToken] {[BeginToken]
const[KeywordToken] A[StringToken]([BeginToken])[SimpleToken] =>[SimpleToken] 0[StringToken],[SimpleToken]
_[StringToken] =>[SimpleToken] 1[StringToken],[SimpleToken]
}[SimpleToken])[SimpleToken];[SimpleToken]
}[SyntheticToken][SimpleToken]