Skip to content

Commit f93aea7

Browse files
kallentuCommit Queue
authored andcommitted
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: #57036 Fixes: #57037 Change-Id: I4e2cab29e33ed266603942eaebf3f9671ef60766 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427802 Reviewed-by: Bob Nystrom <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Michael Thomsen <[email protected]> Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent 58b2ecb commit f93aea7

23 files changed

+260
-54
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,46 @@
22

33
**Released on:** Unreleased
44

5+
### Language
6+
7+
Dart 3.10 adds [dot shorthands][dot-shorthand-spec] to the language. To use
8+
them, set your package's [SDK constraint][language version] lower bound to 3.10
9+
or greater (`sdk: '^3.10.0'`).
10+
11+
#### Dot shorthands
12+
13+
Dot shorthands allow you to omit the type name when accessing a static member
14+
in a context where that type is expected.
15+
16+
These are some examples of ways you can use dot shorthands:
17+
18+
```dart
19+
Color color = .blue;
20+
switch (color) {
21+
case .blue:
22+
print('blue');
23+
case .red:
24+
print('red');
25+
case .green:
26+
print('green');
27+
}
28+
```
29+
30+
```dart
31+
Column(
32+
crossAxisAlignment: .start,
33+
mainAxisSize: .min,
34+
children: widgets,
35+
)
36+
```
37+
38+
To learn more about the feature, check out the
39+
[feature specification][dot-shorthand-spec].
40+
41+
[dot-shorthand-spec]: https://github.com/dart-lang/language/blob/main/working/3616%20-%20enum%20value%20shorthand/proposal-simple-lrhn.md
42+
43+
### Tools
44+
545
#### Dart CLI and Dart VM
646

747
- The Dart CLI and Dart VM have been split into two seperate executables.

pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ enum ExperimentalFlag {
6868

6969
dotShorthands(
7070
name: 'dot-shorthands',
71-
isEnabledByDefault: false,
71+
isEnabledByDefault: true,
7272
isExpired: false,
73-
experimentEnabledVersion: defaultLanguageVersion,
73+
experimentEnabledVersion: const Version(3, 10),
7474
experimentReleasedVersion: const Version(3, 9),
7575
),
7676

pkg/analyzer/lib/src/dart/analysis/experiments.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class ExperimentalFeatures {
269269
isExpired: IsExpired.dot_shorthands,
270270
documentation: 'Shorter dot syntax for static accesses.',
271271
experimentalReleaseVersion: Version.parse('3.9.0'),
272-
releaseVersion: null,
272+
releaseVersion: Version.parse('3.10.0'),
273273
channels: ["stable", "beta", "dev", "main"],
274274
);
275275

@@ -648,7 +648,7 @@ class IsEnabledByDefault {
648648
static const bool digit_separators = true;
649649

650650
/// Default state of the experiment "dot-shorthands"
651-
static const bool dot_shorthands = false;
651+
static const bool dot_shorthands = true;
652652

653653
/// Default state of the experiment "enhanced-enums"
654654
static const bool enhanced_enums = true;

pkg/analyzer/test/generated/recovery_parser_test.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,7 @@ class B = Object with A {}''',
483483
void test_dotShorthand_missing_identifier() {
484484
var result = parseExpression(
485485
".",
486-
codes: [
487-
ParserErrorCode.missingIdentifier,
488-
ParserErrorCode.experimentNotEnabled,
489-
ParserErrorCode.experimentNotEnabled,
490-
],
486+
codes: [ParserErrorCode.missingIdentifier],
491487
);
492488
var expression = result as DotShorthandPropertyAccess;
493489
expect(expression.period.lexeme, '.');

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ analysisOptions
403403
constructor-tearoffs
404404
control-flow-collections
405405
digit-separators
406+
dot-shorthands
406407
enhanced-enums
407408
extension-methods
408409
generic-metadata
@@ -484,6 +485,7 @@ analysisOptions
484485
constructor-tearoffs
485486
control-flow-collections
486487
digit-separators
488+
dot-shorthands
487489
enhanced-enums
488490
extension-methods
489491
generic-metadata

pkg/analyzer_testing/lib/experiments/experiments.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:analyzer/dart/analysis/features.dart';
1616
/// whether a given flag is already included.
1717
List<String> experimentsForTests = [
1818
Feature.augmentations.enableString,
19-
Feature.dot_shorthands.enableString,
2019
Feature.enhanced_parts.enableString,
2120
Feature.macros.enableString,
2221
Feature.variance.enableString,

pkg/front_end/lib/src/api_prototype/experimental_flags_generated.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ class ExperimentalFlag {
118118

119119
static const ExperimentalFlag dotShorthands = const ExperimentalFlag(
120120
name: 'dot-shorthands',
121-
isEnabledByDefault: false,
121+
isEnabledByDefault: true,
122122
isExpired: false,
123-
enabledVersion: defaultLanguageVersion,
124-
experimentEnabledVersion: defaultLanguageVersion,
123+
enabledVersion: const Version(3, 10),
124+
experimentEnabledVersion: const Version(3, 10),
125125
experimentReleasedVersion: const Version(3, 9));
126126

127127
static const ExperimentalFlag enhancedEnums = const ExperimentalFlag(

pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.expect

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ library;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: This requires the experimental 'dot-shorthands' language feature to be enabled.
6-
// Try passing the '--enable-experiment=dot-shorthands' command line option.
7-
// test() => A.const.toString();
8-
// ^
9-
//
105
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'.
116
// Try inserting an identifier before 'const'.
127
// test() => A.const.toString();

pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.modular.expect

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ library;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: This requires the experimental 'dot-shorthands' language feature to be enabled.
6-
// Try passing the '--enable-experiment=dot-shorthands' command line option.
7-
// test() => A.const.toString();
8-
// ^
9-
//
105
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'.
116
// Try inserting an identifier before 'const'.
127
// test() => A.const.toString();

pkg/front_end/testcases/constructor_tearoffs/issue46133.dart.strong.transformed.expect

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ library;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:18: Error: This requires the experimental 'dot-shorthands' language feature to be enabled.
6-
// Try passing the '--enable-experiment=dot-shorthands' command line option.
7-
// test() => A.const.toString();
8-
// ^
9-
//
105
// pkg/front_end/testcases/constructor_tearoffs/issue46133.dart:7:13: Error: Expected an identifier, but got 'const'.
116
// Try inserting an identifier before 'const'.
127
// test() => A.const.toString();

0 commit comments

Comments
 (0)