Commit Graph

133 Commits

Author SHA1 Message Date
Jens Johansen fd4e41a7af [parser-ish] Better errors on invalid unicode escapes
https://github.com/dart-lang/sdk/issues/48542

Change-Id: Icbdcc939a93c737914091c00aaefa3c4efb2dde0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237364
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-03-17 13:57:45 +00:00
Jens Johansen 6969a6edd3 [parser] Don't leak a rewrite when swallowing an error
The old code tries to determine something by using a forwarding listener
without forwarding to anything. It leaked a rewrite though, meaning that
the rewrite stayed, but the error given when rewriting wasn't passed on.

When then parsing it with the real listener, the rewrite was in effect
and there was no error to report. In total no errors were reported.

This fixes the issue by undoing any rewrites in this situation.

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

Change-Id: I5342ae6969f00dea830fb7abb30f21932907b8bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236540
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-03-10 18:43:46 +00:00
Jens Johansen f40d76d360 [parser] Recover missing () for enum constant with type arguments or dot
Fixes https://github.com/dart-lang/sdk/issues/48380

Change-Id: I4f6fd7311c46ad45ccce5bf6b97b40932a457851
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234360
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-03-09 12:40:35 +00:00
Konstantin Shcheglov 9dc81176ab [parser] Better recovery on empty named argument name
Fixes https://github.com/dart-lang/sdk/issues/48288

Change-Id: I831b4870ba7dc69436f68e1ef84e0cdf258073a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234289
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-03-09 09:55:44 +00:00
Johnni Winther fa05359f2f [cfe] Support augmentation library imports
This adds support for the `import augment <uri>` import syntax when
the 'macros' experiment is enabled.

The CL also include propagation of the augment modifier on class methods
which was missed in a previous CL.

Change-Id: Ic843e7e34559bcac728c810590f34b727b5f7090
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234401
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-28 11:42:34 +00:00
Jens Johansen 514f678199 [parser] Better recovery for extra stuff in enum and using enum as identifier
Fixes https://github.com/dart-lang/sdk/issues/48371

Change-Id: I93331485c884c89c179c2fa332f3f975db9507f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234043
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-02-25 09:35:25 +00:00
Jens Johansen 468f939428 [parser] Better recovery for missing comma in initializer list.
Fixes https://github.com/dart-lang/sdk/issues/48411

Change-Id: I5212b15cf9f8749653dbced1c86d0e3e9c163d98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234041
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-02-23 18:12:32 +00:00
Johnni Winther cd41e43c48 [parser] Support 'augment' as a built-in identifier for augmentation libraries
This changes the way the 'augment' modifier is handled in the parser.
Instead of being special cased for class declarations, it is now a
built-in identifier recognized only when the scanner is configured to
support augmentation libraries.

The change supports the used of the 'augment' modifier on not only
class declarations but also mixin and member declarations, as needed
for supporting macros.

Change-Id: I2679d198dea360900cfc478fae9c1660702a8a02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233887
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-23 16:17:42 +00:00
Chloe Stefantsova c12238d3ac [cfe] Allow typed super parameters
Part of https://github.com/dart-lang/sdk/issues/47525

Closes https://github.com/dart-lang/sdk/issues/47741
Closes https://github.com/dart-lang/sdk/issues/48444
Closes https://github.com/dart-lang/sdk/issues/47951

Change-Id: If9aadd996414df5091fc667a7202aafa9a0213db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233889
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-02-23 13:10:33 +00:00
Chloe Stefantsova 53cdbfb5f7 [cfe] Preserve correct enum elements to avoid cascading errors
Part of https://github.com/dart-lang/sdk/issues/47453

Change-Id: Ic79a7667e5eb1b4cf27c1d1628312e4d8c052304
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-02-21 11:06:10 +00:00
Johnni Winther 2435848b13 [parser] Support 'augment' modifier on class declarations
This adds support for the 'augment' modifier on class declarations
needed for the static meta-programming prototype.

Change-Id: Iadd11f766a195076405f2803b2092199caf1ea8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233180
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-18 09:39:23 +00:00
Jens Johansen a066e2c83e [parser] Don't be overly aggressive when parsing 'on' in 'try'
Fixes https://github.com/dart-lang/sdk/issues/47541

Change-Id: Idb25f86801b14f75fe7bc06e5496c6fdd2cbe971
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230243
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-01-31 09:09:35 +00:00
Konstantin Shcheglov e8098caeab Field formal parameter identifier is a declaration.
Change-Id: I70bdf7af8f2663a056b8b9be65f5ea23a105d2f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-15 20:37:53 +00:00
Chloe Stefantsova 384aeb3533 [cfe] Add support for factories and methods in enums
Part of https://github.com/dart-lang/sdk/issues/47453

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

Change-Id: If96b17220df63b5f0089e302322fad2735354d5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226687
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-01-10 11:59:49 +00:00
Konstantin Shcheglov 2766add19a Partial fix for parsing explicitly typed super formal parameters.
I need at least this much to cover a few test cases in the analyzer,
but it might be not the best implementation. It seems to not break
anything, so maybe we can land this for now, while we are waiting for
the better fix of the referenced issue?

Bug: https://github.com/dart-lang/sdk/issues/47951
Change-Id: I428e32f4435b3229cb2dc41678182cde0e2f98e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226200
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-04 16:19:06 +00:00
Johnni Winther 8cdc0e6474 [analyzer,cfe] Add support for macro class
This CL add the 'macros' experiment and adds support for the `macro`
modifier on class declarations. This is part of the prototyping of
the static meta-programming feature.

Change-Id: Ie4b8c5443fda3813307ea076c315baad6a90c3e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224205
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-12-21 10:45:59 +00:00
Sam Rawlins cb34251c5c Support for three-word references in Doc Comments
This expands the front_end's and analyzer's support for doc comment
references to include `/// [a.b.c]`. Such a reference must be to a
getter, setter, method, or constructor of a class or extension which
is referenced with an import prefix, such as `[async.Future.value]`.

In the existing support for two words, the two words are named
"prefix" and "token". In a three-word reference, the _first_ word
must be an import prefix, but I've chosen the new names,
"leadingPrefix", "prefix", and "token", to minimize the change.

If an improved change is desirable, considering the names from scratch,
I might choose something like "prefix", "container", and "identifier".
But these names will be applied to one-word and two-word references as
well, so `[async.Future]`, a reference to the Future class provided by
an import prefixed as 'async', would have a 'prefix' of null, a
'container' of 'async', and an identifier of 'Future'.

Bug: https://github.com/dart-lang/sdk/issues/47444
Change-Id: I7758ec16872677221c456dd1dd6dc2a4df0f6102
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/223661
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-12-14 23:51:10 +00:00
Chloe Stefantsova 7359264b13 Revert "[parser] Add support for typed super-initializer parameters"
This reverts commit fc9f7e3372.

Reason for revert: breakages in ternary operators involving super access.

Original change's description:
> [parser] Add support for typed super-initializer parameters
>
> Part of https://github.com/dart-lang/sdk/issues/47525
>
> Closes https://github.com/dart-lang/sdk/issues/47741
>
> Bug: https://github.com/dart-lang/sdk/issues/47741
> Change-Id: I0558b33aa43cc73e67ca0d17bd5c8ec1afdc526f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221634
> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: https://github.com/dart-lang/sdk/issues/47741
Change-Id: I565faadeb0776a089853dc2264af50b069e16056
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222301
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2021-12-07 18:52:49 +00:00
Chloe Stefantsova fc9f7e3372 [parser] Add support for typed super-initializer parameters
Part of https://github.com/dart-lang/sdk/issues/47525

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

Bug: https://github.com/dart-lang/sdk/issues/47741
Change-Id: I0558b33aa43cc73e67ca0d17bd5c8ec1afdc526f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221634
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-12-06 10:31:57 +00:00
Chloe Stefantsova 312eb812c8 [parser][analyzer][cfe] Add parsing support for enhanced enums
Part of https://github.com/dart-lang/sdk/issues/47453.

Change-Id: I3a722cbcca6323b751eb3b2429bb9ffb642972b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217011
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2021-12-03 17:05:39 +00:00
Chloe Stefantsova 46cf1b9dd6 [parser][analyzer][cfe] Add parsing support for super-parameters
Part of https://github.com/dart-lang/sdk/issues/47525

Change-Id: I7b824e5e3fc9dbb2c6416dfd15df274037a8e9e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219521
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-11-19 16:56:07 +00:00
Johnni Winther 44e35b1daa [cfe] Check for misplaced type arguments on implicit creation expression
Change-Id: Ic3436f2bce0369d0efad9946cbbdae7c6bf334b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218400
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2021-10-28 19:21:39 +00:00
Chloe Stefantsova a666b5a72b [analyzer,parser] Check for named before positional in analyzer
Since the check or the absence of the check for a named argument
appearing before a positional parameter is feature-specific
considering the language feature that allows placing the named
arguments anywhere, it should be performed by the listeners of the
parser and guarded by an experiment flag, in alignment with other
experimental featuers. This CL moves the check and the reporting of
the error from the parser into the Analyzer, so that later this check
can be skipped if the corresponding experiment flag is enabled.

Part of https://github.com/dart-lang/sdk/issues/47451.

Change-Id: Ib795d418af429ee04ecfff6dfa71ec1e836fe798
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216640
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <dmitryas@google.com>
2021-10-14 13:25:23 +00:00
Sam Rawlins 20da76f9f8 Update parser to allow unnamed constructor reference in comment reference
Code like `/// See also [List.new].` will be accepted as a valid comment
reference.

Test in front_end, analyzer, analysis_server.

Remove TODOs in analyzer for reporting a reference to an element whose
library is not the library in which the comment is found.

Bug: https://github.com/dart-lang/sdk/issues/47446
Change-Id: Ifa19278f92ac003082b62b121c66f0559c0152e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216583
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-10-13 14:09:26 +00:00
Johnni Winther 3171c7cc0e [cfe] Remove UnresolvedType
All NamedTypeBuilder objects from user code contain the needed file uri
and char offset.

Change-Id: Ia067c5ef740967302aa207eaf2d46fc2f75c1c8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215600
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-10-06 07:39:34 +00:00
Johnni Winther cf1591f935 [cfe] Refactor detection of instance type variable access in static context
NamedTypeBuilder is now created with a state that determines whether it
can validly be resolved to an instance type variable.

Change-Id: I1e7f5f8e05a5f68ec18a063476b6cda291a1aca8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214643
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-10-05 11:58:04 +00:00
Paul Berry b2c2acee09 Adjust front end nomenclature for error messages.
This change updates the classes Message, MessageCode, Template,
LocatedMessage, and FormattedMessage so that they uniformly refer to
error message text using the terminology `problemMessage` and to
correction suggestions using the terminology `correctionMessage`.
This brings them into alignment with the names we've decided to use to
unify the structure of front_end and analyzer, and makes them match
the names used in the anlayzer and front end's `messages.yaml` files.

Change-Id: Idcbb7ccfff6bb4e99ca22a3ef3c19d83880cf3c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215154
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-10-04 13:32:46 +00:00
Johnni Winther 2fa89236d7 [cfe] Handle potentially constant types in instantiations
Part of https://github.com/dart-lang/sdk/issues/46232

Closes #47154

Change-Id: I71fe16d26facf29bdae1b98971c4ccfe18f95e80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213772
Reviewed-by: Chloe Stefantsova <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-09-23 09:04:12 +00:00
Jens Johansen 497a331365 [parser] Set 'recovered' in more cases
Fixes https://github.com/dart-lang/sdk/issues/47009
Fixes https://github.com/dart-lang/sdk/issues/47008

Change-Id: I4d00e378ad7cfe3b84fe0f48b11cb83ad7a14fc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212826
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-09-10 08:18:17 +00:00
Dmitry Stefantsov ab508bb2d1 [cfe] Add basic parsing support for extension show clause
Change-Id: I63847a06ff7370dd1b92fc6b4b706c684f15638e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209909
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
2021-09-07 10:35:12 +00:00
Jens Johansen 1231e3dad4 [parser] Better error message for >>> when not enabled in some cases (part 2)
https://github.com/dart-lang/sdk/issues/46886

Change-Id: I6195ad921f5c4b9622c735cb919c2d88f957f374
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211820
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-09-01 11:12:28 +00:00
Paul Berry 1b4f067e0b Parser: Reduce the set of disambiguation tokens for resolving < ambiguities.
When the parser encounters a `<` after an expression, it must choose
whether to interpret it as a relational operator or a <typeArguments>
selector.  The disambiguation rule is: if the `<` and the tokens
following it *can* be parsed as <typeArguments>, and the token that
follows is a member of a privileged set of tokens, then it is treated
as a <typeArguments> selector; otherwise it is treated as a relational
operator.

This change reduces the privileged set of tokens to the following:

- the "continuation tokens" `(`, `.`, `==`, and `!=`
- the "stop tokens" `)`, `]`, `}`, `;`, `:`, and `,`

The names "continuation tokens" and "stop tokens" reflect the
rationale for choosing these tokens:

- Continuation tokens are tokens that we can reasonably imagine a
  programmer wanting to place after a type argument selector to
  *continue* the expression.  For example, `if (List<int> == T) ...`
  is allowed.

- Stop tokens are tokens that can't possibly follow a `>` that is a
  relational operator, because they *stop* the expression that's in
  progress.  For example, `var x = List<int>;` is allowed.

If a user wants to follow a <typeArguments> selector with a token
other than the ones above, they'll have to parenthesize the
expression.  So for example, if they want to do `List<int> + 1` (which
could be meaningful if an extension method defined `operator +` for
the type `Type`), they will have to use parentheses, and instead write
`(List<int>) + 1`.

Bug: https://github.com/dart-lang/language/issues/1806
Change-Id: I2816cdac24e55eac3cb3e9920e276404c1228d46
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210941
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-08-27 14:56:16 +00:00
Johnni Winther ce4e7705f2 [cfe] Handle explicit instantiation in implicit creation syntax
Closes #46719
Closes #46887

Change-Id: I4ad0f1bb4ab847a44f749113c6446f62a474143c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211260
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-08-26 11:59:48 +00:00
Jens Johansen 72de10d938 [parser] Better error message for >>> when not enabled in some cases
https://github.com/dart-lang/sdk/issues/46886

Change-Id: Ib204d0c9a7116aaff0f0079be51d551c3f89316d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211003
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-08-26 10:58:20 +00:00
Johnni Winther 2a5c85e7cf [parser] Add useImplicitCreationExpression
This flag prepares for the removal of the special case of implicit
creation syntax, `foo<bar>.baz()`, which with constructor-tearoffs
doesn't have to be a creation expression. Since both the analyzer
and the CFE needs to support parsering without special casing
before it can be removed, the flag is added to ensure both
implementations will agree on what the future parser behavior will be.

The CL hard-wires the CFE use of the parser to a single constant value.

Change-Id: I04724f039d2e698f3cf67e8b0b56dfa7e96ed3b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211000
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-08-25 11:44:53 +00:00
Jens Johansen 7399e4e631 [parser] Recover differently when formal parameter name is keyword
Fixes https://github.com/dart-lang/sdk/issues/46736

Change-Id: Ia8ee921e14ac80934f9d0ec14e0140b23cc7d3bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210725
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-08-23 15:14:47 +00:00
Jens Johansen 5e00baa329 [parser] Format files and add /* name = */ comments
Change-Id: I701c3b0cc0c4d4210a8d81efe2d3683cec4f7f88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210721
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-08-23 07:27:47 +00:00
Jens Johansen 7bf731a547 [parser] Special-casing of '}' (like eof) wrt. looksLikeName
Change-Id: I55fb4c10931831630f9c1621addef7fbe9d5a9d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205797
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-08-19 06:41:58 +00:00
Paul Berry 8dc6c5ecb0 Allow is or as to follow type arguments in constructor tearoff disambiguation.
Fixes #46888.

Bug: https://github.com/dart-lang/sdk/issues/46888
Change-Id: I780a53a2d5a45a8630935c9be5c886d96ef1a2ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209881
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-08-13 15:41:31 +00:00
Paul Berry ee38656c0b Fix corner cases of type argument parsing.
Fixes #46635.

Bug: https://github.com/dart-lang/sdk/issues/46635
Change-Id: I4f74f5ad39bfc775f69e4a47892725e1f166f962
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207201
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-07-19 11:28:29 +00:00
Johnni Winther 49e2148dea [cfe] Migrate wave 10 aka the big one
Change-Id: I77a1996fe3ebd3605efc5afc6ff3308f6ebc3cac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205580
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-07-07 15:18:02 +00:00
Jens Johansen 56df34c8a0 [parser] Don't eat '>>' and '>>>' when ensuring identifier for type variable declaration
This gives better recovery for
https://github.com/dart-lang/sdk/issues/46505
because previously it would ignore (logically delete) '>>', insert an
identifier after, then recover more by inserting '>' and '>'.
Now it instead inserts the identifier before, and the '>>' is later
split into '>' and '>'.

Change-Id: I9e23fde4fc1281424e63ac0ce2b3c9fc85a68772
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205787
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-07-06 07:14:40 +00:00
Jens Johansen f56dd3f887 [parser] Don't .next to get to an endGroup we're already past
This should technically fix
https://github.com/dart-lang/sdk/issues/46505
but the recovery is still pretty weird.

Change-Id: Ieca7fc1cd680af49f4b6f2f0c280b22d4a23ae15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205786
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-07-05 12:24:07 +00:00
Jens Johansen e75d26b76c [parser] Attempt to crash instead of inserting after eof
In reference to https://github.com/dart-lang/sdk/issues/46505 I'd say
it's strictly better to crash than to (get the Analyzer to) go into
an infinite loop.

Change-Id: I6706353061272c8df19f156da6fb6659e3b0e30a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205785
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-07-05 08:21:37 +00:00
Jens Johansen 4a49580e7e [parser] Consume (and use) identifier looking like start of next top level declaration as class name
Fixes https://github.com/dart-lang/sdk/issues/46346

Change-Id: Ie688d0838b612c2eda157bbf9e2fa799bae96fb1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203762
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-06-18 10:20:32 +00:00
Jens Johansen 7798c3af14 [parser] Different recovery for symbols with non-identifiers
Instead of getting errors like this:

```
t.dart:6:4: Error: Expected an identifier, but got 'class'.
Try inserting an identifier before 'class'.
  #class.foo;
   ^^^^^
t.dart:6:4: Error: Expected ';' after this.
  #class.foo;
   ^^^^^
t.dart:6:4: Error: 'class' can't be used as an identifier because it's a keyword.
Try renaming this to be an identifier that isn't a keyword.
  #class.foo;
   ^^^^^
t.dart:6:4: Error: Getter not found: 'class'.
  #class.foo;
   ^^^^^
```

we get something like this:

```
t.dart:6:4: Error: 'class' can't be used as an identifier because it's a keyword.
Try renaming this to be an identifier that isn't a keyword.
  #class.foo;
   ^^^^^
```

https://github.com/dart-lang/sdk/issues/46208
https://github.com/dart-lang/sdk/issues/46207

Change-Id: I79da73e600f732d10020c871d11e11c3f7fe740a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203686
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-06-18 08:29:11 +00:00
Dmitry Stefantsov 9c5ac01504 [cfe] Parse 'extension type' phrase when the experiment is enabled
Change-Id: I5db09d82b26ecd6e95bd2ba753eee5304c00a491
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201268
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-06-16 15:30:27 +00:00
Paul Berry 40a1ae7fc0 Add parser support for use of new as a constructor name.
The new "constructor tearoffs" feature includes the ability to use the
`new` keyword in a place where an identifier is expected, and that
identifier could denote a constructor name.  We handle this by
replacing the `new` keyword token with an identifier token whose
identifier string is `new` (this should ease the burden on the
implementations, since they are already set up to handle constructor
names that are identifiers).

Since all such situations follow a `.`, and `new` was never previously
allowed after a `.`, the parser treats `new` as an identifier in any
situation where it could possibly refer to a constructor, regardless
of whether the "constructor tearoffs" feature is enabled.  (This
should allow for easier error recovery in the situation where the user
tries to use the feature with a language feature that does not support
it).  It is up to the client to report an error if the feature is
disabled.

In this CL, I've implemented logic for the analyzer to choose whether
to report an error based on whether the feature is enabled.  I've
implemented logic for the CFE to report the error unconditionally.

Bug: https://github.com/dart-lang/sdk/issues/46020, https://github.com/dart-lang/sdk/issues/46044
Change-Id: I36a496688400d2d9f699dd42be4d0ba620cda244
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201961
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-06-02 18:02:35 +00:00
Paul Berry 126c5fa680 Initial parser support for constructor tear-offs.
This CL adds parser support for use of `<typeArguments>` as a
selector.  This allows expressions like `List<int>` (type literal with
type arguments), `f<int>` (function tear-off with type arguments),
`C.m<int>` (static method tear-off with type arguments), `EXPR.m<int>`
(instance method tear-off with type arguments), and `EXPR<int>`
(tear-off of `.call` method with type arguments).

I will add parser support for `.new` as a constructor name in a
follow-up CL.

Change-Id: I157e732276421e8c3fd20c38c67ae9643993bd85
Bug: https://github.com/dart-lang/sdk/issues/46020, https://github.com/dart-lang/sdk/issues/46044.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197102
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-05-25 13:58:10 +00:00
Jens Johansen 7ef0841386 [parser] Don't use potential type arguments if they came via recovery
A few places in the parser we call `computeTypeParamOrArg` and then
either use the result or not depending on whether there's a `(` after
it. That doesn't work well when `computeTypeParamOrArg` does recovery
by for instance inserting a > though.
This CL fixes that - at least in the places we know about.

Fixes #45848.

Change-Id: Id4b62b965131031f43c8ada0fe05045fc9834db3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197360
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2021-05-03 07:30:28 +00:00