Commit Graph

866 Commits

Author SHA1 Message Date
Konstantin Shcheglov 303d907237 Add Pattern type variable to TypeAnalyzer.
Change-Id: I3d88b0337689efecffac228c9acf03a5a52229d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267461
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-11-04 19:23:37 +00:00
Paul Berry 402a05de1b Add record type parsing to mini_types.dart.
We now no longer need the `expr2` function to test expressions whose
type is RecordType.

Also added unit tests of the type parser in mini_types.dart (which was
previously tested only by virtue of its use in other tests).

Change-Id: I5d351f3ff924676b4d84e65c8949f42feca0dab9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267522
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-11-03 19:41:47 +00:00
Paul Berry 941056459a Change NamedType to not extend Type
The NamedType class in mini_types.dart doesn't really represent a type
in the same way that the other subclasses of Type do; it's simply a
pairing of a name and a type.

Change-Id: I20709e66a44da4afbf187984c2032b315c1cc21e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267287
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-11-03 17:35:39 +00:00
Konstantin Shcheglov d27d206108 Add analyzeRecordPattern() to the shared TypeAnalyzer.
Change-Id: I10e582a32f60db8bba8acf1f9cc8578469c51f77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267442
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-11-02 21:06:33 +00:00
Konstantin Shcheglov 45fb04020d Merge TypeOperations2 into TypeOperations.
Change-Id: I957192cc72385f70cdd038a2e38b4ca4a0606bb7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266804
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2022-11-02 14:11:28 +00:00
Johnni Winther 5baa4af7d8 [analyzer,cfe] Add 'views' feature and support for 'view class'
This adds the 'views' feature flag together with parser support
for 'view class'. If the feature is not enabled, an error is reported.

TEST=pkg/front_end/parser_testcases/views/...

Change-Id: I813ac86a0e7de9f0a5729c6d7ae35b82d1258ae5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265780
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2022-11-02 11:09:59 +00:00
Konstantin Shcheglov bf9a9a7abd Add analyzeRelationalPattern() to the shared TypeAnalyzer.
Not sure if this is has much value in comparison to the existed
implementation in the analyzer.

We also have private implementations for extractor and record
patterns in the analyzer. I don't know yet for sure how (if) we will
share these, but if we do, it might be something like this one.

Change-Id: I86070bcf922a58fbf1087c7ab42c6eb5695c1475
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266861
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-11-01 22:56:25 +00:00
Chloe Stefantsova 85a841e881 [cfe] Combine Matchers and Binders into Patterns
Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: I1400d854d722e8280b9d0d66c9e1630829542aa5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266682
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-10-31 16:18:23 +00:00
Chloe Stefantsova a9a915ee7b [cfe] Report errors on private fields in records
Closes https://github.com/dart-lang/sdk/issues/50144

Change-Id: I7cbf2fd30773269b5f839299f948da719f3eecc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263781
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-10-28 10:38:52 +00:00
Konstantin Shcheglov f282fcfa35 Prepare to publish analyzer 5.2.0 and _fe_analyzer_shared 50.0.0
Change-Id: Iebf909af9e62322d898d6db79ee5fa6f8bfe3899
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265561
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-25 21:03:37 +00:00
Srujan Gaddam 8c62ad7596 [pkg:js] Validate createStaticInteropMock
This revisits the validation after the redesign. The changes from
before the redesign include:
- Accounting for multiple extensions on @staticInterop classes
- Users can implement any of the extension members for a given
export name, with the exception that if there is a getter/setter
pair, both should be implemented if any one of them are
- Since this validation goes on top of exports, the Dart class
needs not be processed, and we use the same export creation process
to create the mock

Change-Id: I05a7cff765d6d37d3955dd93676e2d55d2b201b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262862
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-10-24 17:37:09 +00:00
Srujan Gaddam 7f93985005 [pkg:js] Add validation for @JSExport and createDartExport
Creates an external createDartExport function in js_util.

Adds a number of checks for the annotation:
- Classes with the annotation should not have value in the annotation
- Classes with the annotation should have at least one instance member
somewhere in the hierarchy
- There are no export name collisions that are unresolvable accounting
for overrides
- Members with this annotation are instance members with a body only

Also adds checks to createDartExport:
- Checks that the type is a Dart class
- Checks that the type is marked as exportable

Change-Id: I52f27275966e9603e88921ce7897b7615178c4d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259511
Reviewed-by: Riley Porter <rileyporter@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-10-24 17:37:09 +00:00
Ahmed Ashour 5e75bb14a5 [_fe_analyzer_shared] handle $this in String interpolation
Fixes #50263

Change-Id: I4fdfab69a2d462768848f01aceb450f266e09072
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265083
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-10-24 16:41:13 +00:00
Paul Berry 6318d7f2e5 Move "mini-AST" type operations to their own class.
This will allow them to be re-used in other _fe_analyzer_shared test
files.

Change-Id: Ib9c321ba8985241f2ad2c1783e9896f3f1e57408
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264960
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-10-21 19:58:03 +00:00
Chloe Stefantsova 7179750fae [cfe] Report error on Object member names used as record field names
Part of https://github.com/dart-lang/sdk/issues/50143

Closes https://github.com/dart-lang/sdk/issues/50143

Change-Id: I3ad99c6bbf27fcb5f4868f74d5005a9483081627
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263740
Auto-Submit: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-10-21 19:49:37 +00:00
Johnni Winther 8995807b2b [cfe] Create various matcher in the body builder
This add the Expression-, Binary-, Cast-, NullAssert-, NullCheck-, List-
and RelationalMatcher and creates these during body building. The
IfCaseStatement is added to support propagation of these to the
inference visitor.

Change-Id: Ia9add15e504cb06af711efc1697a00b8e235e1a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263128
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2022-10-21 14:01:02 +00:00
Konstantin Shcheglov f14aba03e7 Use shared analyzeIfStatement()
Change-Id: I9271fb21538faeacc0625e8c48f7add860f86e60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264726
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2022-10-19 00:40:47 +00:00
Srujan Gaddam 521cbcdd47 [pkg:js] Disallow external extension members with type parameters
Bug: https://github.com/dart-lang/sdk/issues/49350

Checks to see that external extension members on `@staticInterop` types
do not declare or use a type parameter.

Change-Id: Id8646b599094b748c5490810b64d872065676014
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254103
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-10-18 17:47:29 +00:00
Srujan Gaddam b6526beeab [pkg:js] Disallow staticInterop generative constructors
Fixes https://github.com/dart-lang/sdk/issues/48730

Change-Id: I4c7f687ec8d2724de0e031aa5ebe887f93843761
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254101
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-10-18 17:47:29 +00:00
Paul Berry 5e29849393 Parser: consolidate handleCaseMatch and endCaseExpression.
There was no need for both of these listener callbacks, because they
were always called together.  Since `beginCaseExpression` is actually
used, it makes sense to keep `endCaseExpression` and get rid of
`handleCaseMatch`.

Change-Id: I544096b2c2b2814e8cc0c8606455855cb77c9e60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264102
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-10-15 13:51:59 +00:00
Paul Berry 9aab3c7746 Patterns parsing: add support for guards.
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I21db09c9d8c1d359e1b125eea2bae2749cdb72fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264101
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-10-14 20:14:20 +00:00
Paul Berry 4cf63fb382 Parser and listener API changes for supporting pattern guards.
These are in their own CL so that it's easy to verify that no
functionalty has changed, even though a lot of parser expectations
files are affected.

In a follow-up CL, I'll add code that actually parses pattern guards.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I79f5a02df45e29b69aa4d8348cfdf27042ada9d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264020
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-10-14 15:42:12 +00:00
Paul Berry 5923b883db Parser: add support for wildcard patterns.
The bare identifier `_` is treated as a variable pattern wherever it
appears, even though other bare identifiers are sometimes treated as
constant patterns.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I475ef627b6d0bf519a1972aa5ec683e2d032f02b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263280
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-10-14 14:04:59 +00:00
Jens Johansen 27e0e84cc3 [parser] Allow parsing top-level getter called get that's async/async*/sync*
Change-Id: I07e9759cdf61e1b633bbc0e7cd961d80ecfedf8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263129
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-14 11:21:48 +00:00
Jens Johansen 7aeda010bf [parser] Follow-up on feedback posted after land of record commit
Follow-up to https://dart-review.googlesource.com/c/sdk/+/262605

Change-Id: I5178f7118af30eaa280dde746ddbf579fff5df40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263127
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-10-14 10:57:39 +00:00
Jens Johansen c4ea2d95cd [parser] Add comments to calls
Change-Id: Ide38846a6ff93c0bb7714ad89cc2f14accb0ed20
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263126
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-14 09:48:38 +00:00
Jens Johansen b3dbaadc83 [parser] More corner cases for record types
* required is a modifier when followed by [record type] `?`.
* Parse record type as record type if followed by `super` or `?` `super`
  or `?` `this`.
* Typedef with record type follow by `?`.
* Parse record type as record type in get/set with async/sync/sync*.
* Parse record type as record type when followed by `>>=` or `>>>=`
  (for weird formatted use in typedefs).

Change-Id: I19e208497e28780fb1505139c488e943751cce25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263123
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-10-14 09:33:58 +00:00
Jens Johansen c784cc7500 [parser] Don't always parse question as part of record type
Change-Id: I48468c2531e01a9f535e9d973c57911c28967bcb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262605
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-10-07 10:11:34 +00:00
Jens Johansen 97cdb043da [parser] Parse record type return type for operators
Change-Id: I23b5ef38a9bfd58c327303198e59d9b50ace323b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262681
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-07 08:59:39 +00:00
Jens Johansen 575ae24207 [parser] Parse record type question after modifier
Change-Id: If2dd018a79719bd0f5a9a44f46fb102c3595d08e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261644
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-07 08:52:04 +00:00
Jens Johansen af2f4e2d29 [parser] Parse record type used in optional and named parameters
Fixes https://github.com/dart-lang/sdk/issues/50136

Change-Id: If02c0d86244ef9cd3685256e583b987d438307d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262961
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-10-07 06:39:08 +00:00
Jens Johansen eb80f37103 [parser] Parse record type in for in
Change-Id: I96773ecf597685bd6cdfe7da9971b42aea1488e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262940
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-10-07 06:37:42 +00:00
Jens Johansen e860cf241b [parser] Empty record
https://github.com/dart-lang/language/pull/2535

Change-Id: I8241119ee858ce39673472056b88c9393799e1a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262600
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-10-06 06:34:58 +00:00
Johnni Winther b7debf00f7 [cfe] Handle pattern events in BodyBuilder
This supports pattern listener events in the BodyBuilder without
crashing. Currently no AST is created and only dummy objects are put
on the stack.

Change-Id: I24a29073b578bb9aaa07e84d5177e51428074a94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262422
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-10-04 13:31:41 +00:00
Chloe Stefantsova 1d768f3c75 Reland "Reland "[cfe,corelib] Add class 'Record' to the core library""
This is a reland of commit 4b6a8f35b9

Original change's description:
> Reland "[cfe,corelib] Add class 'Record' to the core library"
>
> Part of https://github.com/dart-lang/sdk/issues/49713
>
> Change-Id: I56bfca49492d14bb561b32993fd9adfe775b7400
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259583
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>

Change-Id: Idaab98c028312ca36bd07f569374ca8b76151a02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260101
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-10-04 12:29:47 +00:00
Paul Berry 118f628ecf Patterns: add support for parsing constant patterns
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I601248bc206d9b19521b020fadb2eccd048e0ec7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261701
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-10-03 19:46:16 +00:00
Jens Johansen 92b97fe6fb [parser] Field formal parameter with explicit record type
Fixes https://github.com/dart-lang/sdk/issues/50007

Change-Id: I4cce2fd49db9a71b344d5d3e3ea1e0a941a434ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262200
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-10-03 07:14:26 +00:00
Paul Berry cba19c0de0 Remove bogus comment from parseLiteralSetOrMapSuffix
This comment was relevant in a previous revision of the patterns
parsing logic and I neglected to revert it.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: Ia4034d66c3cc354e2ea6f2e1485380bccf7333dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261700
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-09-29 12:24:47 +00:00
Jens Johansen a2466e26c5 [parser] Parse nested generics with records
Fixes https://github.com/dart-lang/sdk/issues/50005
Fixes https://github.com/dart-lang/sdk/issues/50057

Change-Id: I6c84f20093b27c4d2f51e7058295257b5d82288e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261642
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-09-29 07:28:47 +00:00
Jens Johansen f9e508a0cc [parser] Parse typedef with record return type
Fixes https://github.com/dart-lang/sdk/issues/49994

Change-Id: I5212b780bdd4e28c7c3afcabc72c9e65f7caecfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261604
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-09-29 06:28:36 +00:00
Jens Johansen 59f895b4ed [parser] Don't pretend like record types doesn't exist in on clause parsing
Fixes https://github.com/dart-lang/sdk/issues/49980

Change-Id: I74c734a64f4c0d4bd6ad79f231411352f6b170c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261362
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-09-28 13:41:56 +00:00
Paul Berry 9eb5544ec1 Parser: split some pattern/expression parsing logic.
This change restores `parseParenthesizedExpressionOrRecordLiteral`,
`parseArguments`, and `parseArgumentsRest` to the way they looked
prior to adding parser support, and instead adds new methods
`parseParenthesizedPatternOrRecordPattern` and
`parseExtractorPatternRest` that are specialized for patterns parsing.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I104e031a796ef7f217cd427e1a9ae94a04dafa7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261620
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2022-09-28 12:50:56 +00:00
Paul Berry 6945a72009 Patterns: initial parser support.
The parser now supports the following subset of the parser grammar:

- logical-or and logical-and patterns (called "binary patterns" to
  reflect analyzer nomenclature)

- extractor patterns

- cast patterns

- list patterns

- map patterns

- null-assert patterns

- null-check patterns

- variable patterns where the variable is preceded by `var`, `final`,
  <type>, or `final <type>`

- if-case statements (and if-case within collections); without guards

- record patterns

- parenthesized patterns

- constant patterns where the constant is a plain expression not
  beginning with `const` (booleanLiteral, nullLiteral, numericLiteral,
  stringLiteral, identifier, or qualifiedName).

- relational patterns

- patterns in switch statements

- integration with the analyzer's AstBuilder class

Not implemented yet:

- constant patterns beginning with `const`

- variable patterns where the variable is a single identifier (note:
  this means that `_` is currently interpreted as a constant pattern
  rather than a "wildcard" variable pattern)

- guards (a.k.a. "when clauses")

- switch expressions

- pattern variable declarations

- patterns appearing in "for loop parts"

- pattern assignment

- several error checking and error recovery scenarios (see TODO
  comments)

- integration with the front_end's BodyBuilder class

- front_end style parser tests (currently the feature is tested using
  analyzer unit tests only)

Note that in patterns, `as` binds has higher precedence than `&` and
`|`, whereas in expressions, `&` and `|` have higher precedence than
`as`.  To reflect this, a new precedence has been added,
CAST_PATTERN_PRECEDENCE.

To reduce the risk to users during parser development, the parser
currently only attempts to parse patterns when instructed to do so
(i.e. when the language feature is enabled).  In the long term, I
intend to change the parser so that it always attempts to parse
patterns, and it is the responsibility of its listener to report
errors if patterns are used without enabling the language feature.

Change-Id: I360b535d2a6ebd35a0ee4d066b06e3ae8e3121ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261020
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-09-27 13:16:33 +00:00
Paul Berry d7e130e930 Patterns parsing: update expectations (no functional change).
For ease in code review, I've made all the changes that affect test
expectations files here, in a way that can easily be confirmed during
code review to have no functional effect on parser semantics.

This will be followed by a change that introduces parser support for
patterns, but doesn't affect test expectations.

Change-Id: I830600c1ae89447c7745bfae6fd91c379b6e05d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261022
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-09-27 12:56:54 +00:00
Jens Johansen 4124e85f09 [parser] Fix shifting that fails on web
This CL uses Martins suggested fix (adding 1 to avoid shifting a
negative), and adds a simple test that compiles the parser to dart2js
(with asserts enabled) and runs it via d8. This will perhaps catch
breakage up front another time.
To my knowledge this is not a supported use case though, so likely
we can't but in much effort for any future big breakages.

Fixes https://github.com/dart-lang/sdk/issues/50048

Change-Id: Ic5ac6e63f2d6d32e38ba562ed21dbe85328935cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261301
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-09-27 10:33:53 +00:00
Konstantin Shcheglov 5a812f423d Prepare to publish analyzer 5.1.0 and _fe_analyzer_shared 49.0.0
Change-Id: I64bbfb67d39a86cf4c3b00067f78c992d0fe2502
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261161
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2022-09-26 18:14:58 +00:00
Sam Rawlins 51114fca8a Unnamed libraries
Fixes https://github.com/dart-lang/language/issues/1073

Spec: https://github.com/dart-lang/language/blob/master/accepted/future-releases/unnamed-libraries/feature-specification.md

This work allows library directives without a name. Every single one would look like this:

```
library;
```

:) it was a little anti-climactic implementing a non-feature like this, but there it is.

The affordance for a library directive without a name is guarded by an experiment flag, `--unnamed-libraries`.

Change-Id: I8612238359e88d6082f7e89d0d0fc624fdb45273
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/257490
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2022-09-23 05:37:39 +00:00
Paul Berry 8da75ede06 Shared type analysis: simplify handling of patterns.
Patterns may need to be visited twice during analysis: once to
determine a type schema, and a second type to resolve the pattern
match.  Previously, the shared TypeAnalyzer had just a single
`dispatchPattern` method, so it had to create temporary objects to
record the structure of the patterns between the two visits.  Now,
there are two dispatch methods: `dispatchPatternSchema` and
`dispatchPattern`.  This avoids the creation of a bunch of temporary
objects and makes the design much simpler.

(Based on an idea from Brian Wilkerson)

Change-Id: If10b6b7fb578594c3f660baa55d7e28123652638
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260282
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-09-22 22:41:32 +00:00
Paul Berry b8eede8c9f Flow analysis: make propertyGet's wholeExpression argument nullable.
This is needed for CFE integration of field type promotion, since it
allows the CFE to call propertyGet in circumstances where there's no
expression corresponding to the property get, such as during an
invocation of a field that's been parsed as a method call.

Change-Id: I1856705c080315e87e283af217be331021ef8aee
Bug: https://github.com/dart-lang/language/issues/2020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260452
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-09-22 17:30:29 +00:00
Paul Berry 043f18f843 Flow analysis: use a callback to check if a property is promotable.
Previously we expected the client to provide a set of promotable
fields, which worked well for testing.  But using a callback gives the
client more flexibility (e.g. it would allow field promotability to be
computed on demand based on other data).

Bug: https://github.com/dart-lang/language/issues/2020
Change-Id: I40683a4c19a17147e86f0faa1339aa025da35229
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256962
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-09-22 13:09:07 +00:00