Commit Graph

379 Commits

Author SHA1 Message Date
Konstantin Shcheglov f8ef9fdb61 Patterns. Fix for parsing nested pattern assigment: 'v2 = (v1) = 0'.
Change-Id: I4b3460dd57834eb52b4703c983ca6f8ed60fe270
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508684
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-06-03 08:52:55 -07:00
Johnni Winther 4070db747a [cfe][PrimaryConstructors] Build initializers in const primary constructors
This updates the handling of initializers in primary constructor body declarations. The parser is updated to pass the `:` token, similar to what is done for the regular constructors. The CFE is updated to use a boolean, rather that the `:` token (or a synthetic token), to determine whether initializers should be processed as part of building the outline. The parsing of initializers is done using the `:` token, if any, now pass both from regular constructors and primary constructor body declarations.

Closes #63468

Change-Id: Ia266dea7946b30b02d56f9f3cedf40848c4ee440
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507401
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-06-02 00:11:19 -07:00
Konstantin Shcheglov b9d3c903a0 Patterns. Report invalidConstantPatternBinary for 'case a.b + c.d'.
Bug: https://github.com/dart-lang/sdk/issues/63356
Change-Id: Id26a0cebf5aa0320e1d3fc62ca630fe8e7716241
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507580
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-06-01 09:53:09 -07:00
Konstantin Shcheglov 4629bff7e9 Augment. Report extensionTypeAugmentationSpecifiesRepresentationField.
Add a syntactic diagnostic for extension type augmentations that declare
representation fields. Extension type augmentations may augment the
declaration, but they must not redeclare the representation.

Thread an explicit parser option through primary constructor parsing so
extension type augmentations can omit a representation without producing
the usual missing-primary-constructor diagnostics, while still reporting
an error when a representation is present.

Register the new diagnostic in the shared and analyzer generated
diagnostic tables and add it to fix status tracking.

Change-Id: I84815bb0669a76126564e590760e93096a3af046
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-22 17:36:54 -07:00
Konstantin Shcheglov 841afc1004 Augment. Parse augment factory.
Change-Id: I81df0fe9db49cb64fa81fbd737c44e364c868cf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502186
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-12 00:24:55 -07:00
Kallen Tu 8bfb683892 Enable 'primary-constructors' feature flag.
This CL enables the primary constructors feature by default in Dart 3.13.

The primary constructors feature is a brevity feature. There are no new semantics, but it allows us to express declarations in a less verbose way.

This feature allows one constructor and a set of instance variables to be specified in the header of a declaration.

Currently a declaration with a constructor and some fields is written as:

```dart
// Current syntax.
class Point {
  int x;
  int y;
  Point(this.x, this.y);
}
```

With a primary constructor, we would write the above as:

```
class Point(var int x, var int y);
```

If a primary constructor needs an initializer list or a body, they can be
specified inside the class using the `this` body syntax:

```dart
class Point(var int x, var int y) {
  this : assert(x >= 0) {
    print('Point created at $x, $y');
  }
}
```

As part of this feature, you can also use the `new` and `factory` keywords to
declare constructors in the class body without repeating the class name:
```dart
class Point {
  int x, y;

  // Equivalent to Point(this.x, this.y)
  new(this.x, this.y);

  // Equivalent to Point.origin()
  new origin() : x = 0, y = 0;

  // Equivalent to factory Point.clone(Point other)
  factory clone(Point other) => Point(other.x, other.y);
}
```

To learn more about the feature, check out the feature specification located here: https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md

Tested: Has existing language, CFE, analyzer, analysis server tests.
Bug: https://github.com/dart-lang/sdk/issues/61524
Change-Id: I296f2fcd918b87bf2a1dd00256340759866c2423
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489241
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2026-05-04 15:09:49 -07:00
Johnni Winther 01a26f9022 [parser][cfe][analyze][PrimaryConstructors] Error recovery for primary constructors on mixins and extensions
This adds error recovery for mixin and extension declarations with primary constructors. This avoids cascading errors when primary constructors are used with these declarations which do not support primary constructors.

Closes #63157

Change-Id: I17bfab4a7eabac1c75e7cfb580295dcf619c991d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499180
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-05-01 01:50:43 -07:00
Jens Johansen 4ee8852d77 [CFE/parser] Update 'end' on endLiteralString; Set offset of StringConcatenation to the start; rename 'token' to 'operatorToken' on endBinaryPatterns
* The 'end' token on endLiteralString is now the last token of the
   string, not the next unrelated token.
 * Set the offset of StringConcatenation to the start of the string,
   not the start of the next unrelated token.
 * The 'end' token on endBinaryPatterns is renamed to 'operatorToken'.

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

Tested: Existing
Change-Id: Iae788464008594c21e759570a626971d89688033
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498601
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-30 01:05:23 -07:00
Kallen Tu 77cf3047a3 Dot Shorthands: Const selector chains.
I changed the parsing of const dot shorthands to parse the entire selector chain in `parsePrecedenceExpression` rather than parsing them in `parseConstExpression`. We were originally parsing the initial expression before the `.` and only flagging that as a dot shorthand which prevented any chaining on const constructors. Const expressions with chained methods/property accesses were not being flagged as a dot shorthand so we weren’t saving the context type properly which led to producing the “unknown context type” error.

Before:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor
// (const .someConstCtor) is handled as a dot shorthand, context is
// saved on only this AST and not the outer chain.
// Then we parse the rest of the selector chain (.method())
//
// Error: No context type for (const .someConstCtor.method())
```

After:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor.
// Then we parse the rest of the selector chain (.method())
// (const .someConstCtor.method()) is handled as a dot shorthand, context is saved for this outer node.
//
// OK. No error because we are able to retrieve the type for the
// entire dot shorthand chain.
```

Fixes: https://github.com/dart-lang/sdk/issues/63119
Change-Id: I3308d8eb7ce101466be257aba6b5448921bff136
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2026-04-24 10:40:26 -07:00
Jens Johansen ff5858a2a1 [CFE] Set proper endOffset on constructor from primary constructor
If nothing else it's needed for
https://github.com/dart-lang/sdk/issues/62645.

Change-Id: Ibcc4cdd292cdec0c33a24c337861e1dd54da24f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496981
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2026-04-22 01:19:02 -07:00
Johnni Winther 5b0def4a87 [parser][Augmentations] Remove support for macro class and import augment
These were part of the macros experiments which has been cancelled.

Change-Id: I14071bc8e86025f273a533c313a3194c8eae5190
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495341
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-04-16 02:25:05 -07:00
Konstantin Shcheglov e7c6654312 Augment. Allow abstract top-level variables.
Permit `abstract` on top-level variable declarations when the
augmentations feature is enabled. Previously the parser always reported
`abstract` as extraneous at the top level, which rejected valid syntax
and dropped the modifier before later stages could see it.

Thread the abstract token through top-level field parsing, record it on
`TopLevelVariableDeclaration`, and pass it through the front-end
builders. Reorder the field callback arguments so `augment` precedes
`abstract`, matching the augmentation grammar for incomplete top-level
variables and keeping the parser, listener, and outline plumbing
consistent.

Change-Id: I680414a746b707d483e485702685c95f28a9c9ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-14 16:12:24 -07:00
Johnni Winther 24e1e1feea [parser][cfe][Augmentations] Remove support for augment super
This removes the remaining support for `augment super` in the parser, analyzer and CFE.

`augment super` will not be part of the augmentations feature.

Change-Id: Ie8a185bba067ab6ecf3b3229ecc20d5c284842bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493401
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-08 03:07:32 -07:00
Fedor Shcheglov 03f20472c4 Do not report missingFunctionBody when augmentation flag is set.
Update tests to only expect the flag on Dart version 3.5 and below, before augmentations were implemented.

Change-Id: I0b46392521701ec3846830a9adc04487c7a8541b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-04-01 11:22:35 -07:00
Fedor Shcheglov bc32b13ddc Report diagnostic error for mixin application class augmentation.
Change-Id: I2cffb0b7049180ba4d291c50663eb06c7dfbac92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489780
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-03-27 07:22:55 -07:00
Johnni Winther beff8b11f2 [cfe][PrimaryConstructors] Avoid creating tear-off lowering for abstract classes
A flag that tells whether constructor is in an abstract class, enum or mixin was not correctly passed for primary constructors. This flag determines whether constructor tear-off lowerings are created for backends that use this, such dart2js and dartdevc.

The parser listener is updated to pass a DeclarationKind for primary constructors, similar to what is already done for regular constructors. The enable the CFE to pass the correct flag.

Change-Id: I114417795ae276dfeab9f10a0b0fcbcd2dbfc00b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490541
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-03-26 00:57:59 -07:00
Konstantin Shcheglov e9d8109258 DeCo. Support empty bodies in membered declarations
Allow enums, extensions, and mixins to use `;` as their body and
represent that form explicitly in the AST. The parser now produces
`EmptyEnumBody` or `EmptyClassBody` for the empty form.

Also replace `LibraryIdentifier` with token-based `DottedName` and store
the full token sequence for dotted names. This preserves periods and
source offsets directly in the AST, which keeps printing, selection, and
directive name handling working with the new shape. See
https://github.com/dart-lang/sdk/issues/62819

See https://github.com/dart-lang/language/issues/4645

Google3 presubmit looks green:
https://fusion2.corp.google.com/presubmit/884063020/OCL:884063020:BASE:884079610:1773618867493:b2110d76

Change-Id: I2d023cd03b6423da634c3e14742e02a61dc3b403
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-03-16 08:56:11 -07:00
Johnni Winther 32b6f24e4d [cfe][PrimaryConstructors] Enable features in tests
This enables primary-constructors and private-named-parameters by default in CFE expectation tests.

Test are update accordingly; some are annotated with `@dart=3.10` to opt out of the features, some cloned to support both opt-in and opt-out, and some are modified to use opt-in before only.

Part of #61700

Change-Id: Iae9e5d188d9b49d4264d17dc989dbaeee7321845
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479620
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-02-12 00:38:54 -08:00
Johnni Winther 02cc7229a9 [parser][PrimaryConstructors] Add parser recovery for new.name() constructor
This avoids derailing the parser when '.' is used instead of ' ' in the new constructor syntax.

Part of #61699

Change-Id: I0deef032ff88a8d23e82130e65b54a864268ff26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478561
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-02-06 06:21:26 -08:00
Paul Berry 69a1a497f1 [messages] Stop using withArgumentsOld, batch 32.
This is one of several planned batches of changes to transition the
front end (and related packages) away from the old `withArgumentsOld`
diagnostic reporting method, and to the new `withArguments`
method. The difference between the two is that `withArguments` has
named parameters rather than positional ones, so (a) it's less likely
for parameters to be mixed up, and (b) it's compatible with the
calling conventions used by analyzer diagnostics.

As part of this transition, I'm taking the opportunity to rename the
parameters themselves (since the names previously were restricted to a
very small set of possibilities based on type), and to document them
in `messages.yaml`. To avoid fatigue (both for myself and code
reviewers), I've chosen to break the change into many smaller batches.

The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator, running the script
`use_new_with_arguments.dart`, and then updating front end parser
expectations.

Change-Id: I6a6a6964699f00e7e91af2e682ce1baa1846ca13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478060
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-02-04 10:05:41 -08:00
Paul Berry 50b4225636 [messages] Stop using withArgumentsOld, batch 31.
This is one of several planned batches of changes to transition the
front end (and related packages) away from the old `withArgumentsOld`
diagnostic reporting method, and to the new `withArguments`
method. The difference between the two is that `withArguments` has
named parameters rather than positional ones, so (a) it's less likely
for parameters to be mixed up, and (b) it's compatible with the
calling conventions used by analyzer diagnostics.

As part of this transition, I'm taking the opportunity to rename the
parameters themselves (since the names previously were restricted to a
very small set of possibilities based on type), and to document them
in `messages.yaml`. To avoid fatigue (both for myself and code
reviewers), I've chosen to break the change into many smaller batches.

The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator, running the script
`use_new_with_arguments.dart`, and then regenerating front end parser
test expectations.

Change-Id: I6a6a696461f9184a42d646fab6a593bcb4abdf4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478000
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-02-03 14:17:32 -08:00
Paul Berry d579b03f71 [messages] Use withArguments for diagnostics translated by the analyzer.
Changes the `front_end` and `_fe_analyzer_shared` code that reports
the following diagnostics so that it uses `withArguments` rather than
`withArgumentsOld`:

- `expectedButGot`
- `expectedButGot2`
- `expectedAfterButGot`
- `expectedToken`
- `unmatchedToken`
- `constFieldWithoutInitializer`
- `finalFieldWithoutInitializer`
- `superclassHasNoMethod`
- `unavailableDartLibrary`
- `unsupportedPlatformDartLibraryImport`

These messages required special care because they are translated into
analyzer diagnostics by the analyzer method
`FastaErrorReporter.reportByCode`, and the logic to do the translation
depends on the exact parameter names used by the messages.

For some of the messages I've clarified the parameter names and
updated `FastaErrorReporter.reportByCode` accordingly. For others, I
left the parameter names as is.

Change-Id: I6a6a696481c75f4cbb198d1e012aa1ca4294ed61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476323
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-30 10:12:42 -08:00
Paul Berry e0ce42f22d [messages] Stop using withArgumentsOld, batch 5.
This is one of several planned batches of changes to transition the
front end (and related packages) away from the old `withArgumentsOld`
diagnostic reporting method, and to the new `withArguments`
method. The difference between the two is that `withArguments` has
named parameters rather than positional ones, so (a) it's less likely
for parameters to be mixed up, and (b) it's compatible with the
calling conventions used by analyzer diagnostics.

As part of this transition, I'm taking the opportunity to rename the
parameters themselves (since the names previously were restricted to a
very small set of possibilities based on type), and to document them
in `messages.yaml`. To avoid fatigue (both for myself and code
reviewers), I've chosen to break the change into many smaller batches.

The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_new_with_arguments.dart`.

Change-Id: I6a6a6964d05c7481d886252f77d5c90c9e63a155
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476340
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-30 09:47:33 -08:00
Konstantin Shcheglov 8baa15d70a DeCo. Report extraneousModifier for primary constructor body.
Change-Id: I0b1fcf22d2d5b6fefaf6797ce6cd7317eff1def8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476561
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-01-30 07:53:43 -08:00
Paul Berry ba40413d67 [messages] Stop using withArgumentsOld, batch 4.
This is one of several planned batches of changes to transition the
front end (and related packages) away from the old `withArgumentsOld`
diagnostic reporting method, and to the new `withArguments`
method. The difference between the two is that `withArguments` has
named parameters rather than positional ones, so (a) it's less likely
for parameters to be mixed up, and (b) it's compatible with the
calling conventions used by analyzer diagnostics.

As part of this transition, I'm taking the opportunity to rename the
parameters themselves (since the names previously were restricted to a
very small set of possibilities based on type), and to document them
in `messages.yaml`. To avoid fatigue (both for myself and code
reviewers), I've chosen to break the change into many smaller batches.

The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator, then running the script
`use_new_with_arguments.dart`, then updating parser testcases by
supplying `-DupdateExpectations=true` to
`pkg/front_end/test/unit_test_suites.dart`.

Change-Id: I6a6a6964232d48c9e6d01accc31b5c5acbd9435f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476150
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-28 17:25:51 -08:00
Konstantin Shcheglov 7b7d495d5f DeCo. Report extraneousModifier as appropriate.
Reports `extraneousModifier` when the primary constructors feature is
enabled and `final` or `var` is used in a formal parameter declaration
that's not part of a primary constructor.

Change-Id: I32e530cc60b89a7385e382def7b4c33e90199a7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475343
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-01-26 12:17:40 -08:00
Johnni Winther 01dd5b546e [parser][PrimaryConstructors] Support covariant on non-final declaring parameters
This updates the parser to allow covariant modifier on non-final declaring parameters. A new message is added for the case where primary constructors are support to avoid signaling that it is generally invalid to use covariant in primary constructors.

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

Change-Id: Ic592579e6499a30fb51d74af45bc294fb8213b3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472904
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-01-22 01:24:45 -08:00
Johnni Winther 0a154753c6 [parser][InternalNodes] Add handlePositionalArgument and handlePositionalRecordField
This [handlePositionalArgument] and [handlePositionalRecordField] methods to the parser listener, allowing listeners to normals arguments and record fields

Change-Id: I3947e196dafffea2ab383f797904c857db8327ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469620
Reviewed-by: Jens Johansen <jensj@google.com>
2026-01-06 02:30:12 -08:00
Erik Ernst 02641c88d0 Transfer parser updates of CL449821 into this CL
Specification proposal:
https://github.com/dart-lang/language/blob/main/working/0260-anonymous-methods/feature-specification.md.

Change-Id: I57743ec663633a148087c1be36e492e1e45e406e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464704
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2025-12-04 08:03:41 -08:00
Kallen Tu 2110e90d68 Rename 'declaring-constructors' to 'primary-constructors' experiment flag.
Changed the flag to `primary-constructors` to align with the rest of
the feature's public naming.

Renamed tests and existing usages of the flag.

Bug: https://github.com/dart-lang/sdk/issues/61526
Change-Id: Id649447a50917ba5bcddb49661555889dc81ba14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464761
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
2025-12-01 13:54:52 -08:00
Johnni Winther 17cfd12d31 [parser] Handle factory new() in constructor declaration
This adds error recovery for explicitly naming a factory constructor 'new' with the new constructor syntax. This is not allowed so an error is explicitly emitted while handling this.

Change-Id: I61db5e2abacaebe4f42e44b45a4c3d45faa23377
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-26 03:05:30 -08:00
Johnni Winther 85975b4f44 [parser] Handle new new() in constructor declaration
This adds error recovery for explicitly naming a constructor 'new' with the new constructor syntax. This is not allowed so an error is explicitly emitted while handling this.

Change-Id: Iac3045f04c9c75779ffb2d9e866817ac43ab5d26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463281
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-11-26 03:05:30 -08:00
Johnni Winther a01f697340 [cfe] Handle new constructor syntax
This handles the new constructor syntax in the outline building.

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

Change-Id: Ifd3095f2e092402d114f1f66fd4aeccddf2c7d32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463280
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-21 00:44:53 -08:00
Johnni Winther abfbf952cb [parser] Handle qualified names in new constructor syntax
This improves the error recovery for syntax like `new C.named();`. Previously, the parser would derail with messages like "A method declaration needs an explicit list of parameters" and a cascade of other errors.

With this change the qualified name is recognized as an attemp to write the name of the constructor, reporting that qualified names are not allowed in this case.

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

Change-Id: Id1062aac3b90db8d2346013cf8a0bd9a541b9a3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463020
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-20 00:30:11 -08:00
Johnni Winther 18e6ccadc3 [cfe] Move pre-feature tests
The parser suite now supports `@dart=` annotations so pre-features tests for declaring constructors can be moved to the declaring_constructors subfolder.

Change-Id: I73f4204795ee0d09f664ffa0bb929be356afe0fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463000
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-19 04:16:24 -08:00
Johnni Winther 45679bcac9 [parser] Support new constructor syntax
This adds parser support of the new constructor syntax using `new` instead of the enclosing class name

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

Change-Id: I3de50298e83f431c765a987435324b8c8931eef7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462042
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-19 03:05:01 -08:00
Johnni Winther 808b2512b4 [parser] Add beginConstructor
This adds a beginConstructor listener method and calls this before constructor instead of beginMethod. This makes it possible for listeners to fully separate handling of constructors from methods.

Change-Id: Ibcbcf76ccb6d97314d395c4c0efcb4f9d073519a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-18 05:26:52 -08:00
Johnni Winther d46bd8cf58 [parser] Merge parser listener endX methods
This merges endX methods for non-top-level members into endMethod, endConstructor, endFactory and endFields.

These methods now have a DeclarationKind parameter that can be used to distinguish them.

Change-Id: I458d37a70b6c7839612f7199dad95f9a61e76e7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462120
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-17 04:50:52 -08:00
Johnni Winther 7352e9c044 [parser] Remove getOrSet token from endXConstructor methods
These were never used and just confused implementations about what to handle.

Change-Id: I1fa4868e043a716b60bec107e4ba57018eee63be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460460
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-11 02:54:57 -08:00
Kallen Tu 2692a110f0 [parser] Declaring constructors - Parse primary constructor this body.
Added two listener calls `beginPrimaryConstructorBody` and
`endPrimaryConstructorBody` for parsing the `this` body.
No AST implementation has been done, only parsing.

Bug: https://github.com/dart-lang/sdk/issues/61699
Change-Id: I6aaf621bb3e67bfe00efe32de8097ca1e5048afb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459901
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2025-11-07 13:14:13 -08:00
Johnni Winther 23ea6713f0 [cfe] Fix parser test
Collision with another CL that wasn't caught by the trybots.

Change-Id: I3c6ecfcf87a3bb3f371550bbaaf4f958aeb5d3c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460300
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Johnni Winther <johnniwinther@google.com>
2025-11-07 01:50:37 -08:00
Johnni Winther a58eb47216 [parser] Support new factory constructor syntax
Part of https://github.com/dart-lang/sdk/issues/61699

Change-Id: I6afa9f4991d4b965a60d39e14618731a10a04a1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459820
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-07 00:45:41 -08:00
Johnni Winther be29db2621 [cfe] Update parser suites to use FolderOptions
This updates the parser suites to use the FolderOptions already used by other expectation tests. This aligns the support for configuration tests in particular wrt experimental flags.

As a consequence of this change, all parser suite enable patterns for parser. Since the test setup didn't use experimental flags previously, newly added tests didn't use the current default, which is with pattern support. Since we don't have any tests explicitly for non-pattern support, all tests are updated to support patterns as it at least aligns with the default for current and future code.

Change-Id: I80ee769b35e74a0d111135ca4690983872a63623
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459741
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-06 03:43:55 -08:00
Johnni Winther 633ed8f4ae [parser] Handle empty class/extension type body
This is part of https://github.com/dart-lang/sdk/issues/61699

Change-Id: I93afc3426771c5a179fc77993433ae82aec05ff1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459460
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2025-11-06 01:03:59 -08:00
Johnni Winther e055351442 [parser] Change enum listener calls
This aligns the call to `Listener.beginEnum*` with that of `Listener.beginClass*`. A `beginExtensionPrelude` is added, replacing the call to `beginUncategorizedTopLevelDeclaration` and matching the call to `beginClassOrMixinOrNamedMixinApplicationPrelude` for classes. `beginEnumDeclaration` and `endEnumDeclaration` replaces the `beginEnum`/`endEnum` pair, matching the calls to `beginClassDeclaration`/`endClassDeclaration` with the name and type parameters now available at `beginEnumDeclaration` similar to `beginClassDeclaration`. This helps supporting primary constructors in enums because the enclosing enum can be prepared in `beginEnumDeclaration` before calls to `endPrimaryConstructor`.

Change-Id: I9c1ad55db6e3fcc09ed5ac0c05f5d50db95ae608
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458200
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-10-30 08:50:02 -07:00
Johnni Winther a9c91a1a88 [parser] Support declaring function typed parameters
This adds parser support for using `final` and `var` in function type parameters of primary constructors.

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

Change-Id: I32c0b9ac9700fc6a4ccfdd6c732c3ae3179ad5fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457023
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-10-28 03:01:17 -07:00
Johnni Winther 02c3d9c3f0 [parser] Support declaring parameters
This allows `var int a` in primary constructors when the declaring constructors feature is enabled.

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

Change-Id: I486ad8aa3ddbe09451455b024b3aa9cfbaa9a5e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456340
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-10-22 01:46:47 -07:00
Johnni Winther 49eb514005 [parser] Support primary constructor on classes, enums and extension types
This adds simple support for primary constructors in class, enum and extension type declarations. Declaring formals are not supported yet.

Change-Id: I2fb2cb3a819e38ec4ffe961da4713a871ac29a0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-10-17 01:52:11 -07:00
Jens Johansen 0dd06a287e [scanner] Better recovery for missing end brace in string interpolation
Previous recovery resulted in an outline change and very bad performance
as a result (e.g. in the analyzer).

This takes an analyzer server benchmark from:

```
$ out/ReleaseX64/dart-sdk/bin/dart pkg/analysis_server/tool/benchmark_tools/big_chain_benchmark/lsp_typing_temporarily_missing_end_brace_in_string_interpolation.dart --types=ImportCycleExportChain --sizes=1024
[...]
==================================
size 1024 / CodeType.ImportCycleExportChain:
Initial analysis: 16.173549
Completion after change: 7.824299
Fully done after change: 24.515470
peak virtual memory size: 3941 MB
total program size (virtual): 3941 MB
peak resident set size ("high water mark"): 2125 MB
size of memory portions (rss): 2125 MB
==================================
```

to

```
==================================
size 1024 / CodeType.ImportCycleExportChain:
Initial analysis: 16.989549
Completion after change: 0.332792
Fully done after change: 0.333113
peak virtual memory size: 3817 MB
total program size (virtual): 3635 MB
peak resident set size ("high water mark"): 1983 MB
size of memory portions (rss): 1803 MB
==================================
```

Change-Id: I38478acbd9b0449c6962da7543aa4bd39b22d004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453341
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-10-06 01:38:40 -07:00
Paul Berry 7edd29a89c [front_end] Convert an error message to use named arguments.
Modifies the scanner logic that reports the `AsciiControlCharacter`
error message so that it invokes it using `withArguments` (which
accepts named arguments) rather than the old `withArgumentsOld` (which
accepts positional arguments). The name of the parameter accepted by
this error message has been changed to `character`, to reflect its
usage, and parameter documentation has been added.

This is an exercise to verify that the front end's new `withArguments`
error reporting infrastructure is fully functional. In follow-up CLs,
I plan to introduce some tools to partially automate the process of
updating front end code to use `withArguments` rather than
`withArgumentsOld`.

However, if anyone wishes to start migrating error reporting to the
new scheme before that, they are welcome to do so.

Change-Id: I6a6a6964fc87d6bf551ec4891c56e6106dd9c098
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448239
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-09-04 06:33:02 -07:00