Commit Graph

12 Commits

Author SHA1 Message Date
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
Fedor Shcheglov fe0bdac54f Fix a bug where augmentation was incorrectly associated with the macro feature, rather than the augmentations feature.
Added additional tests to ensure validity of this change.

This didn't cause issues in unit tests, because all of them had macros
enabled in their superclasses.

Add TODO for named mixin applications: mixin application classes can't
be augmented.
(https://github.com/dart-lang/language/blob/main/working/augmentations/feature-specification.md#augmenting-class-like-declarations)

Change-Id: Ieaaec84d16ca8cf6d103c9c905fdfa2c0b7c8ca1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489680
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-03-23 07:26:18 -07:00
Robert Nystrom c82716b216 Enable "private-named-parameters" experiment flag.
TEST=many language, co19, and other tests

Bug: https://github.com/dart-lang/sdk/issues/61629
Change-Id: I24d761cc2dc3fa2707a2486a39bfde1b8e847b1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480384
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2026-02-18 15:26:18 -08:00
Konstantin Shcheglov 20085c0902 DeCo. Don't remove experiment from shared experimentsForTests.
Change-Id: If746609320113a42c161021f7c7328cf79bd46fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465483
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-12-01 16:07:30 -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
Chloe Stefantsova 32eb405d69 [analyzer] Include static-extensions in experimentsForTests
Part of https://github.com/dart-lang/sdk/issues/61484
Part of https://github.com/dart-lang/sdk/issues/61485

Change-Id: I06bfb52304857568330cf35281f6d3e70807918d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-10-20 08:35:13 -07:00
Robert Nystrom 557db62620 Add experiment flag for "Private Named Parameters".
Fix #61631.

Change-Id: If797277e0ff294f11515ccfec845381b07c34a11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453643
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2025-10-07 17:15:11 -07:00
Kallen Tu 4cdf9740e9 Add 'declaring-constructors' experiment flag.
This CL adds the flag for the primary/declaring constructors feature.
We'll develop the feature under this flag.

Bug: https://github.com/dart-lang/sdk/issues/61526
Change-Id: I0318998cef7ee1a306af243f4dc15c65ae9f8d96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453640
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-10-07 11:17:17 -07:00
Kallen Tu f93aea7c54 Enable 'dot-shorthands' feature flag for Dart 3.10
This CL enables the dot shorthand feature by default in Dart 3.10.

Dot shorthands allow you to omit the type name when accessing a static member in a context where that type is expected.

These are some examples of ways you can use dot shorthands:

```dart
Color color = .blue;
switch (color) {
  case .blue:
    print('blue');
  case .red:
    print('red');
  case .green:
    print('green');
}
```

```dart
Column(
  crossAxisAlignment: .start,
  mainAxisSize: .min,
  children: widgets,
)
```

To learn more about the feature, check out the feature specification located here: https://github.com/dart-lang/language/blob/main/working/3616%20-%20enum%20value%20shorthand/proposal-simple-lrhn.md

Tested: Feature tested with language tests and unit tests for the frontends, VM, web.
Bug: https://github.com/dart-lang/sdk/issues/57036
Fixes: https://github.com/dart-lang/sdk/issues/57037
Change-Id: I4e2cab29e33ed266603942eaebf3f9671ef60766
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427802
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-08-18 12:38:35 -07:00
Chloe Stefantsova d6ad61c2ca [analyzer] Collect enabled experiments in experimentsForTests
This CL removes the unnecessary overrides of the `experiments` getter
from the tests and collects the corresponding experiment flags added to
the returned value of the getter in the individual tests to the
'experimentsForTests' list that is used by all tests. Specifically, the
experiments `variance` is enabled for all tests.

The flag `inference_update_1` is removed from the experiments list,
since it's enabled by default. In the tests that explicitly require a
distinction between the flag being enabled and disabled, the getter
`_isEnabled` is overridden and returns a value corresponding to the
test.

The flag `inference_update_4` still appears in one of the overrides of
the `experiments` getter, since enabling it in all tests appears
breaking.

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/430720/comment/4c3f016e_4933f925/

Change-Id: I4d35e3c6259e2f7e6751d180b5790c13f68de1ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434360
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-07-01 22:48:49 -07:00
Chloe Stefantsova 6fa858cfe8 Enable 'getter-setter-error' flag in 3.9
TEST=existing

Change-Id: Ic4a5735adda7cf8ef1565b9356ca277d9b62b064
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430720
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-26 08:08:31 -07:00
Sam Rawlins 2f706c4290 analyzer_testing: move experiments library to analyzer_testing
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: I9c5aa920e9f96f99ea00d6993b5f4dafd415f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426986
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-07 13:12:13 -07:00