Commit Graph

6 Commits

Author SHA1 Message Date
Paul Berry 406bdf33e8 Fix precedence of expression inside relational patterns.
According to the spec, the expression inside a relational pattern is
`bitwiseOrExpression`.  We were only allowing `shiftExpression`.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: Ie1a5746f1060b84e6e1b856a622e89db698b4684
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292285
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-01 16:30:49 +00:00
Johnni Winther d4a73e3b82 [cfe] Report errors on invalid const patterns with explicit 'const'.
Change-Id: I4f5994fd1f0d5e5289684e0da2f03720706f6d28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-02-15 10:34:28 +00:00
Johnni Winther d89ae3c2c6 [parser] Report error on invalid const patterns
This handles the restriction imposed on the expression occurring
within a constant pattern.

Change-Id: I946d85f908609340a61e060c6bdbee143666fd91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-02-09 12:43:31 +00:00
Chloe Stefantsova e925066175 [cfe] Adjust scoping for variable patterns in switch expressions
Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: I32f3ebf6c45afbbdc291d8f919b14266b646b998
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278347
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-01-05 15:49:44 +00:00
Paul Berry 38cab10852 Patterns parsing: track when variable patterns are in an assignment context.
Variable patterns behave so differently inside a patternAssignment
that we may want to represent them using different AST nodes inside
the analyzer/CFE.  This change adds a boolean flag allowing the
implementation to know what kind of variable pattern it's looking at
when parsing occurs.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I60adf2865bbe24f85b72a79b1360833bf823bd67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273829
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2022-12-07 22:45:40 +00:00
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