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>
This commit is contained in:
Kallen Tu
2026-05-04 15:09:49 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 7e2f4855d4
commit 8bfb683892
51 changed files with 561 additions and 373 deletions
+64
View File
@@ -2,6 +2,70 @@
**Released on:** Unreleased
### Language
Dart 3.13 adds [primary constructors][primary-constructor-spec] to the language.
To use this feature, set your package's [SDK constraint][language version] lower
bound to 3.13 or greater (`sdk: '^3.13.0'`).
#### Primary constructors
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);
}
```
Now you can write:
```dart
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][primary-constructor-spec].
[primary-constructor-spec]: https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md
### Libraries
#### `dart:async`
@@ -236,9 +236,9 @@ enum ExperimentalFlag {
primaryConstructors(
name: 'primary-constructors',
isEnabledByDefault: false,
isEnabledByDefault: true,
isExpired: false,
experimentEnabledVersion: defaultLanguageVersion,
experimentEnabledVersion: const Version(3, 13),
experimentReleasedVersion: const Version(3, 12),
),
+4 -3
View File
@@ -1495,14 +1495,15 @@ constructorWithWrongName:
analyzerCode: invalidConstructorName
hasPublishedDocs: false
script:
- >-
- |
class A { B.foo() {} }
- >-
- |
// @dart=3.11
class A {
factory B() => new A.internal();
A.internal();
}
- >-
- |
class A {
factory B.foo() => new A.internal();
A.internal();
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -452,24 +451,19 @@ void f() {
@reflectiveTest
class PreferFinalParametersBulkTest extends BulkFixProcessorTest {
@override
List<String> get experiments => super.experiments
.where(
(experiment) => experiment != Feature.primary_constructors.enableString,
)
.toList();
@override
String get lintCode => LintNames.prefer_final_parameters;
Future<void> test_singleFile() async {
await resolveTestCode('''
// @dart = 3.12
void fn(String test, int other) {
print(test);
print(other);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn(final String test, final int other) {
print(test);
print(other);
@@ -480,13 +474,6 @@ void fn(final String test, final int other) {
@reflectiveTest
class PreferFinalParametersTest extends FixProcessorLintTest {
@override
List<String> get experiments => super.experiments
.where(
(experiment) => experiment != Feature.primary_constructors.enableString,
)
.toList();
@override
FixKind get kind => DartFixKind.makeFinal;
@@ -495,6 +482,7 @@ class PreferFinalParametersTest extends FixProcessorLintTest {
Future<void> test_class_constructor() async {
await resolveTestCode('''
// @dart = 3.12
class C {
C(String content) {
print(content);
@@ -502,6 +490,7 @@ class C {
}
''');
await assertHasFix('''
// @dart = 3.12
class C {
C(final String content) {
print(content);
@@ -512,6 +501,7 @@ class C {
Future<void> test_class_requiredCovariant() async {
await resolveTestCode('''
// @dart = 3.12
class C {
void fn({required covariant String test}) {
print(test);
@@ -519,6 +509,7 @@ class C {
}
''');
await assertHasFix('''
// @dart = 3.12
class C {
void fn({required covariant final String test}) {
print(test);
@@ -529,11 +520,13 @@ class C {
Future<void> test_closure_hasType() async {
await resolveTestCode('''
// @dart = 3.12
void fn() {
['1', '2', '3'].forEach((String string) => print(string));
}
''');
await assertHasFix('''
// @dart = 3.12
void fn() {
['1', '2', '3'].forEach((final String string) => print(string));
}
@@ -542,11 +535,13 @@ void fn() {
Future<void> test_closure_noType() async {
await resolveTestCode('''
// @dart = 3.12
void fn() {
['1', '2', '3'].forEach((string) => print(string));
}
''');
await assertHasFix('''
// @dart = 3.12
void fn() {
['1', '2', '3'].forEach((final string) => print(string));
}
@@ -555,11 +550,13 @@ void fn() {
Future<void> test_functionLiteral() async {
await resolveTestCode('''
// @dart = 3.12
var fn = (String test) {
print(test);
};
''');
await assertHasFix('''
// @dart = 3.12
var fn = (final String test) {
print(test);
};
@@ -568,11 +565,13 @@ var fn = (final String test) {
Future<void> test_named_optional() async {
await resolveTestCode('''
// @dart = 3.12
void fn({String? test}) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn({final String? test}) {
print(test);
}
@@ -581,11 +580,13 @@ void fn({final String? test}) {
Future<void> test_named_optional_withDefault() async {
await resolveTestCode('''
// @dart = 3.12
void fn({String test = 'value'}) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn({final String test = 'value'}) {
print(test);
}
@@ -594,11 +595,13 @@ void fn({final String test = 'value'}) {
Future<void> test_named_required() async {
await resolveTestCode('''
// @dart = 3.12
void fn({required String test}) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn({required final String test}) {
print(test);
}
@@ -607,11 +610,13 @@ void fn({required final String test}) {
Future<void> test_positional_optional() async {
await resolveTestCode('''
// @dart = 3.12
void fn([String? test]) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn([final String? test]) {
print(test);
}
@@ -620,11 +625,13 @@ void fn([final String? test]) {
Future<void> test_positional_optional_withDefault() async {
await resolveTestCode('''
// @dart = 3.12
void fn([String? test = 'value']) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn([final String? test = 'value']) {
print(test);
}
@@ -633,11 +640,13 @@ void fn([final String? test = 'value']) {
Future<void> test_simple_hasType() async {
await resolveTestCode('''
// @dart = 3.12
void fn(String test) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn(final String test) {
print(test);
}
@@ -646,11 +655,13 @@ void fn(final String test) {
Future<void> test_simple_noType() async {
await resolveTestCode('''
// @dart = 3.12
void fn(test) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn(final test) {
print(test);
}
@@ -659,11 +670,13 @@ void fn(final test) {
Future<void> test_simple_nullable() async {
await resolveTestCode('''
// @dart = 3.12
void fn(String? test) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.12
void fn(final String? test) {
print(test);
}
@@ -672,14 +685,14 @@ void fn(final String? test) {
Future<void> test_simple_second() async {
await resolveTestCode('''
// @dart = 3.10
// @dart = 3.12
void fn(final String test, String other) {
print(test);
print(other);
}
''');
await assertHasFix('''
// @dart = 3.10
// @dart = 3.12
void fn(final String test, final String other) {
print(test);
print(other);
@@ -689,13 +702,13 @@ void fn(final String test, final String other) {
Future<void> test_simple_var() async {
await resolveTestCode('''
// @dart = 3.10
// @dart = 3.12
void fn(var test) {
print(test);
}
''');
await assertHasFix('''
// @dart = 3.10
// @dart = 3.12
void fn(final test) {
print(test);
}
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -21,13 +20,6 @@ void main() {
@reflectiveTest
class RemoveLexemeAvoidFinalParameters extends FixProcessorLintTest {
@override
List<String> get experiments => super.experiments
.where(
(experiment) => experiment != Feature.primary_constructors.enableString,
)
.toList();
@override
FixKind get kind => DartFixKind.removeLexeme;
@@ -863,13 +855,6 @@ class C {}
@reflectiveTest
class RemoveLexemeVarWithNoTypeAnnotationTest extends FixProcessorLintTest {
@override
List<String> get experiments => super.experiments
.where(
(experiment) => experiment != Feature.primary_constructors.enableString,
)
.toList();
@override
FixKind get kind => DartFixKind.removeLexeme;
@@ -604,7 +604,7 @@ class ExperimentalFeatures {
isExpired: IsExpired.primary_constructors,
documentation: 'Less verbose constructors.',
experimentalReleaseVersion: Version.parse('3.12.0'),
releaseVersion: null,
releaseVersion: Version.parse('3.13.0'),
channels: ["stable", "beta", "dev", "main"],
);
@@ -866,7 +866,7 @@ class IsEnabledByDefault {
static const bool patterns = true;
/// Default state of the experiment "primary-constructors"
static const bool primary_constructors = false;
static const bool primary_constructors = true;
/// Default state of the experiment "private-named-parameters"
static const bool private_named_parameters = true;
@@ -424,6 +424,7 @@ analysisOptions
nonfunction-type-aliases
null-aware-elements
patterns
primary-constructors
private-named-parameters
records
sealed-class
@@ -507,6 +508,7 @@ analysisOptions
nonfunction-type-aliases
null-aware-elements
patterns
primary-constructors
private-named-parameters
records
sealed-class
@@ -582,7 +582,7 @@ EnumDeclaration
enum E;
''');
parseResult.assertErrors([
error(diag.experimentNotEnabledOffByDefault, 22, 1),
error(diag.experimentNotEnabled, 22, 1),
]);
var node = parseResult.findNode.singleEnumDeclaration;
@@ -213,7 +213,7 @@ ExtensionDeclaration
extension E on int;
''');
parseResult.assertErrors([
error(diag.experimentNotEnabledOffByDefault, 34, 1),
error(diag.experimentNotEnabled, 34, 1),
]);
var node = parseResult.findNode.singleExtensionDeclaration;
@@ -254,7 +254,7 @@ MixinDeclaration
mixin M;
''');
parseResult.assertErrors([
error(diag.experimentNotEnabledOffByDefault, 23, 1),
error(diag.experimentNotEnabled, 23, 1),
]);
var node = parseResult.findNode.singleMixinDeclaration;
@@ -417,7 +417,7 @@ enum E;
await assertErrorsInCode(code, [
error(diag.enumWithoutConstants, 21, 1),
error(diag.experimentNotEnabledOffByDefault, 22, 1),
error(diag.experimentNotEnabled, 22, 1),
]);
var node = findNode.singleEnumDeclaration;
@@ -243,7 +243,7 @@ ExtensionDeclaration
// @dart = 3.10
extension E on int;
''',
[error(diag.experimentNotEnabledOffByDefault, 34, 1)],
[error(diag.experimentNotEnabled, 34, 1)],
);
var node = findNode.singleExtensionDeclaration;
@@ -92,7 +92,7 @@ mixin M;
''';
await assertErrorsInCode(code, [
error(diag.experimentNotEnabledOffByDefault, 23, 1),
error(diag.experimentNotEnabled, 23, 1),
]);
var node = findNode.singleMixinDeclaration;
@@ -17,7 +17,6 @@ import 'package:analyzer/dart/analysis/features.dart';
List<String> experimentsForTests = List.unmodifiable([
Feature.augmentations.enableString,
Feature.enhanced_parts.enableString,
Feature.primary_constructors.enableString,
Feature.static_extensions.enableString,
Feature.variance.enableString,
]);
@@ -9,17 +9,17 @@ import 'package:expect/expect.dart';
import '../helpers/compiler_helper.dart';
const String FOO = r"""
void foo(var a, var b) {
void foo(a, b) {
}
""";
const String BAR = r"""
void bar(var eval, var $eval) {
void bar(eval, $eval) {
}
""";
const String PARAMETER_AND_TEMP = r"""
void bar(var t0, var b) {
void bar(t0, b) {
{
var t0 = 2;
if (b) {
@@ -62,7 +62,7 @@ foo(param1, param2, param3) {
""";
const String PARAMETER_INIT = r"""
void foo(var start, var test) {
void foo(start, test) {
var result = start;
if (test) {
foo(1, 2);
@@ -24,7 +24,7 @@ const MEMORY_SOURCE_FILES = const {
}
class C {
foo(var x, var y) {
foo(x, y) {
var arguments, eval;
arguments = x + y;
eval = x - y;
@@ -45,14 +45,14 @@ import '$import2' as js2;
class A {
external get foo;
external A(var foo);
external A(foo);
}
@js2.JS('BClass')
class B {
external get foo;
external B(var foo);
external B(foo);
}
@js1.JS()
+2 -2
View File
@@ -39,14 +39,14 @@ import 'package:js/js.dart';
class A {
external get foo;
external A(var foo);
external A(foo);
}
@JS('BClass')
class B {
external get foo;
external B(var foo);
external B(foo);
}
@JS()
@@ -285,9 +285,9 @@ class ExperimentalFlag {
static const ExperimentalFlag primaryConstructors = const ExperimentalFlag(
name: 'primary-constructors',
isEnabledByDefault: false,
isEnabledByDefault: true,
isExpired: false,
experimentEnabledVersion: defaultLanguageVersion,
experimentEnabledVersion: const Version(3, 13),
experimentReleasedVersion: const Version(3, 12),
);
+14 -4
View File
@@ -6616,6 +6616,7 @@ enumNonConstConstructor:
parameters: none
problemMessage: "Generative enum constructors must be marked as 'const'."
script: |
// @dart=3.11
enum Foo {
bar;
@@ -7484,14 +7485,20 @@ implementMultipleExtensionTypeMembers:
representationFieldModifier:
parameters: none
problemMessage: "Representation fields can't have modifiers."
script: |
extension type E(final int foo) {}
script:
- |
// @dart=3.11
extension type E(final int foo) {}
- |
extension type E(var int foo) {}
expectedRepresentationType:
parameters: none
problemMessage: "Expected a representation type."
script: |
extension type E(var foo) {}
script:
- |
// @dart=3.11
extension type E(var foo) {}
expectedRepresentationField:
parameters: none
@@ -7535,6 +7542,7 @@ representationFieldTrailingComma:
parameters: none
problemMessage: "The representation field can't have a trailing comma."
script: |
// @dart=3.11
extension type E(int foo,) {}
wrongTypeParameterVarianceInSuperinterface:
@@ -7555,12 +7563,14 @@ namedParametersInExtensionTypeDeclaration:
parameters: none
problemMessage: "Extension type declarations can't have named parameters."
script: |
// @dart=3.11
extension type E(int foo, {dynamic bar}) {}
optionalParametersInExtensionTypeDeclaration:
parameters: none
problemMessage: "Extension type declarations can't have optional parameters."
script: |
// @dart=3.11
extension type E(int foo, [dynamic bar]) {}
classImplementsDeferredClass:
@@ -1,66 +1,66 @@
Problems reported:
parser/primary_constructors/constructor_head_pre_feature:4:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:4:3: This requires the 'primary-constructors' language feature to be enabled.
new ();
^^^
parser/primary_constructors/constructor_head_pre_feature:5:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:5:3: This requires the 'primary-constructors' language feature to be enabled.
new () : x = 0;
^^^
parser/primary_constructors/constructor_head_pre_feature:6:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:6:3: This requires the 'primary-constructors' language feature to be enabled.
new () {}
^^^
parser/primary_constructors/constructor_head_pre_feature:7:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:7:3: This requires the 'primary-constructors' language feature to be enabled.
new () : x = 0 {}
^^^
parser/primary_constructors/constructor_head_pre_feature:8:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:8:9: This requires the 'primary-constructors' language feature to be enabled.
const new ();
^^^
parser/primary_constructors/constructor_head_pre_feature:9:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:9:9: This requires the 'primary-constructors' language feature to be enabled.
const new () : x = 0;
^^^
parser/primary_constructors/constructor_head_pre_feature:10:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:10:9: This requires the 'primary-constructors' language feature to be enabled.
const new () {}
^^^
parser/primary_constructors/constructor_head_pre_feature:11:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:11:9: This requires the 'primary-constructors' language feature to be enabled.
const new () : x = 0 {}
^^^
parser/primary_constructors/constructor_head_pre_feature:12:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:12:3: This requires the 'primary-constructors' language feature to be enabled.
new named();
^^^
parser/primary_constructors/constructor_head_pre_feature:13:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:13:3: This requires the 'primary-constructors' language feature to be enabled.
new named() : x = 0;
^^^
parser/primary_constructors/constructor_head_pre_feature:14:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:14:3: This requires the 'primary-constructors' language feature to be enabled.
new named() {}
^^^
parser/primary_constructors/constructor_head_pre_feature:15:3: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:15:3: This requires the 'primary-constructors' language feature to be enabled.
new named() : x = 0 {}
^^^
parser/primary_constructors/constructor_head_pre_feature:16:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:16:9: This requires the 'primary-constructors' language feature to be enabled.
const new named();
^^^
parser/primary_constructors/constructor_head_pre_feature:17:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:17:9: This requires the 'primary-constructors' language feature to be enabled.
const new named() : x = 0;
^^^
parser/primary_constructors/constructor_head_pre_feature:18:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:18:9: This requires the 'primary-constructors' language feature to be enabled.
const new named() {}
^^^
parser/primary_constructors/constructor_head_pre_feature:19:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/constructor_head_pre_feature:19:9: This requires the 'primary-constructors' language feature to be enabled.
const new named() : x = 0 {}
^^^
@@ -1,134 +1,134 @@
Problems reported:
parser/primary_constructors/declaring_parameter_pre_feature:7:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:7:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var a b) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:9:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:9:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:10:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:10:9: This requires the 'primary-constructors' language feature to be enabled.
class C(final f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:11:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:11:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:11:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:11:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:12:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:12:9: This requires the 'primary-constructors' language feature to be enabled.
class C(final void f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:13:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:13:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:14:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:14:9: This requires the 'primary-constructors' language feature to be enabled.
class C(final f<T>()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:15:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:15:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:15:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:15:9: This requires the 'primary-constructors' language feature to be enabled.
class C(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:16:9: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:16:9: This requires the 'primary-constructors' language feature to be enabled.
class C(final void f<T>()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:23:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:23:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var a b) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:25:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:25:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:26:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:26:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(final f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:27:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:27:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:27:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:27:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:28:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:28:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(final void f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:29:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:29:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:30:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:30:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(final f<T>()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:31:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:31:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:31:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:31:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:32:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:32:8: This requires the 'primary-constructors' language feature to be enabled.
enum E(final void f<T>()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:39:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:39:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var a b) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:41:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:41:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:42:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:42:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(final f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:43:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:43:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:43:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:43:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var void f()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:44:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:44:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(final void f()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:45:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:45:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:46:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:46:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(final f<T>()) {}
^^^^^
parser/primary_constructors/declaring_parameter_pre_feature:47:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:47:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:47:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:47:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(var void f<T>()) {}
^^^
parser/primary_constructors/declaring_parameter_pre_feature:48:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/declaring_parameter_pre_feature:48:19: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(final void f<T>()) {}
^^^^^
@@ -1,386 +1,386 @@
Problems reported:
parser/primary_constructors/no_class_extension_type_body_pre_feature:2:8: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:2:8: This requires the 'primary-constructors' language feature to be enabled.
class C;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:3:18: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:3:18: This requires the 'primary-constructors' language feature to be enabled.
class C extends O;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:4:31: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:4:31: This requires the 'primary-constructors' language feature to be enabled.
class C extends O implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:5:38: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:5:38: This requires the 'primary-constructors' language feature to be enabled.
class C extends O with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:6:25: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:6:25: This requires the 'primary-constructors' language feature to be enabled.
class C extends O with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:7:21: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:7:21: This requires the 'primary-constructors' language feature to be enabled.
class C implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:8:28: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:8:28: This requires the 'primary-constructors' language feature to be enabled.
class C with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:9:15: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:9:15: This requires the 'primary-constructors' language feature to be enabled.
class C with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:10:11: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:10:11: This requires the 'primary-constructors' language feature to be enabled.
class C<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:11:24: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:11:24: This requires the 'primary-constructors' language feature to be enabled.
class C<T> extends O<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:12:40: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:12:40: This requires the 'primary-constructors' language feature to be enabled.
class C<T> extends O<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:13:50: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:13:50: This requires the 'primary-constructors' language feature to be enabled.
class C<T> extends O<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:14:34: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:14:34: This requires the 'primary-constructors' language feature to be enabled.
class C<T> extends O<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:15:27: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:15:27: This requires the 'primary-constructors' language feature to be enabled.
class C<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:16:37: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:16:37: This requires the 'primary-constructors' language feature to be enabled.
class C<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:17:21: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:17:21: This requires the 'primary-constructors' language feature to be enabled.
class C<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:18:10: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:18:10: This requires the 'primary-constructors' language feature to be enabled.
class C();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:19:20: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:19:20: This requires the 'primary-constructors' language feature to be enabled.
class C() extends O;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:20:33: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:20:33: This requires the 'primary-constructors' language feature to be enabled.
class C() extends O implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:21:40: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:21:40: This requires the 'primary-constructors' language feature to be enabled.
class C() extends O with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:22:27: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:22:27: This requires the 'primary-constructors' language feature to be enabled.
class C() extends O with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:23:23: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:23:23: This requires the 'primary-constructors' language feature to be enabled.
class C() implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:24:30: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:24:30: This requires the 'primary-constructors' language feature to be enabled.
class C() with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:25:17: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:25:17: This requires the 'primary-constructors' language feature to be enabled.
class C() with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:26:13: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:26:13: This requires the 'primary-constructors' language feature to be enabled.
class C<T>();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:27:26: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:27:26: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() extends O<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:28:42: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:28:42: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() extends O<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:29:52: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:29:52: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() extends O<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:30:36: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:30:36: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() extends O<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:31:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:31:29: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:32:39: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:32:39: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:33:23: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:33:23: This requires the 'primary-constructors' language feature to be enabled.
class C<T>() with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:34:16: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:34:16: This requires the 'primary-constructors' language feature to be enabled.
class const C();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:35:26: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:35:26: This requires the 'primary-constructors' language feature to be enabled.
class const C() extends O;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:36:39: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:36:39: This requires the 'primary-constructors' language feature to be enabled.
class const C() extends O implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:37:46: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:37:46: This requires the 'primary-constructors' language feature to be enabled.
class const C() extends O with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:38:33: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:38:33: This requires the 'primary-constructors' language feature to be enabled.
class const C() extends O with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:39:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:39:29: This requires the 'primary-constructors' language feature to be enabled.
class const C() implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:40:36: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:40:36: This requires the 'primary-constructors' language feature to be enabled.
class const C() with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:41:23: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:41:23: This requires the 'primary-constructors' language feature to be enabled.
class const C() with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:42:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:42:19: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:43:32: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:43:32: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() extends O<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:44:48: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:44:48: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() extends O<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:45:58: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:45:58: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() extends O<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:46:42: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:46:42: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() extends O<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:47:35: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:47:35: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:48:45: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:48:45: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:49:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:49:29: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>() with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:50:16: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:50:16: This requires the 'primary-constructors' language feature to be enabled.
class C.named();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:51:26: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:51:26: This requires the 'primary-constructors' language feature to be enabled.
class C.named() extends O;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:52:39: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:52:39: This requires the 'primary-constructors' language feature to be enabled.
class C.named() extends O implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:53:46: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:53:46: This requires the 'primary-constructors' language feature to be enabled.
class C.named() extends O with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:54:33: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:54:33: This requires the 'primary-constructors' language feature to be enabled.
class C.named() extends O with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:55:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:55:29: This requires the 'primary-constructors' language feature to be enabled.
class C.named() implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:56:36: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:56:36: This requires the 'primary-constructors' language feature to be enabled.
class C.named() with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:57:23: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:57:23: This requires the 'primary-constructors' language feature to be enabled.
class C.named() with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:58:19: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:58:19: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:59:32: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:59:32: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() extends O<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:60:48: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:60:48: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() extends O<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:61:58: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:61:58: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() extends O<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:62:42: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:62:42: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() extends O<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:63:35: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:63:35: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:64:45: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:64:45: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:65:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:65:29: This requires the 'primary-constructors' language feature to be enabled.
class C<T>.named() with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:66:22: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:66:22: This requires the 'primary-constructors' language feature to be enabled.
class const C.named();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:67:32: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:67:32: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() extends O;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:68:45: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:68:45: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() extends O implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:69:52: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:69:52: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() extends O with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:70:39: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:70:39: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() extends O with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:71:35: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:71:35: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:72:42: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:72:42: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() with M implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:73:29: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:73:29: This requires the 'primary-constructors' language feature to be enabled.
class const C.named() with M;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:74:25: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:74:25: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named();
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:75:38: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:75:38: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() extends O<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:76:54: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:76:54: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() extends O<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:77:64: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:77:64: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() extends O<T> with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:78:48: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:78:48: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() extends O<T> with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:79:41: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:79:41: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:80:51: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:80:51: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() with M<T> implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:81:35: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:81:35: This requires the 'primary-constructors' language feature to be enabled.
class const C<T>.named() with M<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:83:25: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:83:25: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:84:38: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:84:38: This requires the 'primary-constructors' language feature to be enabled.
extension type ET(int i) implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:85:28: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:85:28: This requires the 'primary-constructors' language feature to be enabled.
extension type ET<T>(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:86:44: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:86:44: This requires the 'primary-constructors' language feature to be enabled.
extension type ET<T>(int i) implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:87:31: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:87:31: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:88:44: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:88:44: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET(int i) implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:89:34: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:89:34: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET<T>(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:90:50: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:90:50: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET<T>(int i) implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:91:31: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:91:31: This requires the 'primary-constructors' language feature to be enabled.
extension type ET.named(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:92:44: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:92:44: This requires the 'primary-constructors' language feature to be enabled.
extension type ET.named(int i) implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:93:34: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:93:34: This requires the 'primary-constructors' language feature to be enabled.
extension type ET<T>.named(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:94:50: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:94:50: This requires the 'primary-constructors' language feature to be enabled.
extension type ET<T>.named(int i) implements I<T>;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:95:37: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:95:37: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET.named(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:96:50: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:96:50: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET.named(int i) implements I;
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:97:40: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:97:40: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET<T>.named(int i);
^
parser/primary_constructors/no_class_extension_type_body_pre_feature:98:56: This requires the experimental 'primary-constructors' language feature to be enabled.
parser/primary_constructors/no_class_extension_type_body_pre_feature:98:56: This requires the 'primary-constructors' language feature to be enabled.
extension type const ET<T>.named(int i) implements I<T>;
^
@@ -3,7 +3,7 @@ library;
// Problems in library:
//
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:6:20: Error: The 'primary-constructors' language feature is disabled for this library.
// Try removing the `@dart=` annotation or setting the language version to the current release or higher.
// Try removing the `@dart=` annotation or setting the language version to 3.12 or higher.
// extension type ET1(var int a) {}
// ^^^
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:5:1: Context: This is the annotation that opts out this library from the 'primary-constructors' language feature.
@@ -3,7 +3,7 @@ library;
// Problems in library:
//
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:6:20: Error: The 'primary-constructors' language feature is disabled for this library.
// Try removing the `@dart=` annotation or setting the language version to the current release or higher.
// Try removing the `@dart=` annotation or setting the language version to 3.12 or higher.
// extension type ET1(var int a) {}
// ^^^
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:5:1: Context: This is the annotation that opts out this library from the 'primary-constructors' language feature.
@@ -3,7 +3,7 @@ library;
// Problems in library:
//
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:6:20: Error: The 'primary-constructors' language feature is disabled for this library.
// Try removing the `@dart=` annotation or setting the language version to the current release or higher.
// Try removing the `@dart=` annotation or setting the language version to 3.12 or higher.
// extension type ET1(var int a) {}
// ^^^
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:5:1: Context: This is the annotation that opts out this library from the 'primary-constructors' language feature.
@@ -3,7 +3,7 @@ library;
// Problems in library:
//
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:6:20: Error: The 'primary-constructors' language feature is disabled for this library.
// Try removing the `@dart=` annotation or setting the language version to the current release or higher.
// Try removing the `@dart=` annotation or setting the language version to 3.12 or higher.
// extension type ET1(var int a) {}
// ^^^
// pkg/front_end/testcases/general/declaring_parameter_pre_feature.dart:5:1: Context: This is the annotation that opts out this library from the 'primary-constructors' language feature.
+6
View File
@@ -1586,6 +1586,7 @@ LinterLintCode:
parameter `a` is marked as `final`:
```dart
// @dart=3.12
void f([!final!] String a) {
print(a);
}
@@ -1595,6 +1596,7 @@ LinterLintCode:
closure parameter `a` is marked as `final`:
```dart
// @dart=3.12
var f = ([!final!] int a) => print(a);
```
@@ -10248,6 +10250,7 @@ LinterLintCode:
isn't a `final` parameter:
```dart
// @dart=3.12
String f([!String s!]) => s;
```
@@ -10256,6 +10259,7 @@ LinterLintCode:
Add the modifier `final` to the parameter:
```dart
// @dart=3.12
String f(final String s) => s;
```
deprecatedDetails: |-
@@ -17513,6 +17517,7 @@ LinterLintCode:
parameter `x` is declared with `var`:
```dart
// @dart=3.12
void f([!var!] x) {
print(x);
}
@@ -17522,6 +17527,7 @@ LinterLintCode:
initializing formal parameter `x` is declared with `var`:
```dart
// @dart=3.12
class C {
int x;
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -17,28 +16,25 @@ void main() {
@reflectiveTest
class AvoidFinalParametersPrePrimaryConstructorsTest extends LintRuleTest {
@override
List<String> get experiments => super.experiments
.where((e) => e != Feature.primary_constructors.enableString)
.toList();
@override
String get lintRule => LintNames.avoid_final_parameters;
test_constructorFieldFormal_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int p;
C(final this.p);
}
''',
[error(diag.unnecessaryFinal, 23, 5)],
[error(diag.unnecessaryFinal, 37, 5)],
);
}
test_constructorFieldFormal_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int p;
C(this.p);
@@ -49,16 +45,18 @@ class C {
test_constructorSimple_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
C(final int p);
}
''',
[lint(14, 5)],
[lint(28, 5)],
);
}
test_constructorSimple_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
C(int p);
}
@@ -68,17 +66,19 @@ class C {
test_enum_constructor_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
enum E {
a(1);
const E(final int p);
}
''',
[lint(27, 5)],
[lint(41, 5)],
);
}
test_enum_constructor_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
enum E {
a(1);
const E(int p);
@@ -89,17 +89,19 @@ enum E {
test_enum_method_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
enum E {
a;
void f(final p) {}
}
''',
[lint(23, 5)],
[lint(37, 5)],
);
}
test_enum_method_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
enum E {
a;
void f(int p) {}
@@ -110,16 +112,18 @@ enum E {
test_extension_method_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
extension E on int {
void f(final p) {}
}
''',
[lint(30, 5)],
[lint(44, 5)],
);
}
test_extension_method_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
extension E on int {
void f(int p) {}
}
@@ -129,16 +133,18 @@ extension E on int {
test_extensionType_method_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
extension type E(int i) {
void f(final p) {}
}
''',
[lint(35, 5)],
[lint(49, 5)],
);
}
test_extensionType_method_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
extension type E(int i) {
void f(int p) {}
}
@@ -148,14 +154,16 @@ extension type E(int i) {
test_functionExpression_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
var f = (final int value) {};
''',
[lint(9, 5)],
[lint(23, 5)],
);
}
test_functionExpression_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
var f = (int value) {};
''');
}
@@ -163,17 +171,19 @@ var f = (int value) {};
test_functionTyped_fieldFormal_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
final void Function(int) f;
C(void this.f(final p));
}
''',
[lint(56, 5)],
[lint(70, 5)],
);
}
test_functionTyped_fieldFormal_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
final void Function(int) f;
C(void this.f(int p));
@@ -185,14 +195,16 @@ class C {
// No lint because a warning already exists for this case.
await assertDiagnostics(
r'''
// @dart=3.12
void f(final p()) {}
''',
[error(diag.functionTypedParameterVar, 7, 5)],
[error(diag.functionTypedParameterVar, 21, 5)],
);
}
test_functionTyped_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int p()) {}
''');
}
@@ -200,14 +212,16 @@ void f(int p()) {}
test_functionTyped_parameter_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(void g(final p)) {}
''',
[lint(14, 5)],
[lint(28, 5)],
);
}
test_functionTyped_parameter_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(void g(int p)) {}
''');
}
@@ -215,6 +229,7 @@ void f(void g(int p)) {}
test_functionTyped_superFormal_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class A {
A(void f(int p));
}
@@ -222,12 +237,13 @@ class B extends A {
B(void super.f(final p));
}
''',
[lint(69, 5)],
[lint(83, 5)],
);
}
test_functionTyped_superFormal_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class A {
A(void f(int p));
}
@@ -240,16 +256,18 @@ class B extends A {
test_localFunction_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f() {
void g(final p) {}
}
''',
[lint(20, 5)],
[lint(34, 5)],
);
}
test_localFunction_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f() {
void g(int p) {}
}
@@ -259,16 +277,18 @@ void f() {
test_mixin_method_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
mixin M {
void f(final p) {}
}
''',
[lint(19, 5)],
[lint(33, 5)],
);
}
test_mixin_method_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
mixin M {
void f(int p) {}
}
@@ -278,16 +298,18 @@ mixin M {
test_operator_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int operator +(final int other) => 0;
}
''',
[lint(27, 5)],
[lint(41, 5)],
);
}
test_operator_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int operator +(int other) => 0;
}
@@ -297,14 +319,16 @@ class C {
test_optionalNamed_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({final int? p}) {}
''',
[lint(8, 5)],
[lint(22, 5)],
);
}
test_optionalNamed_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({int? p}) {}
''');
}
@@ -312,14 +336,16 @@ void f({int? p}) {}
test_optionalPositional_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f([final int? p]) {}
''',
[lint(8, 5)],
[lint(22, 5)],
);
}
test_optionalPositional_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([int? p]) {}
''');
}
@@ -327,14 +353,16 @@ void f([int? p]) {}
test_optionalPositionalWithDefault_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f([final int p = 0]) {}
''',
[lint(8, 5)],
[lint(22, 5)],
);
}
test_optionalPositionalWithDefault_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([int p = 0]) {}
''');
}
@@ -342,14 +370,16 @@ void f([int p = 0]) {}
test_requiredNamed_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({required final int? p}) {}
''',
[lint(17, 5)],
[lint(31, 5)],
);
}
test_requiredNamed_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({required int p}) {}
''');
}
@@ -357,14 +387,16 @@ void f({required int p}) {}
test_requiredPositional_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(final int p) {}
''',
[lint(7, 5)],
[lint(21, 5)],
);
}
test_requiredPositional_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int p) {}
''');
}
@@ -374,23 +406,26 @@ void f(int p) {}
// https://github.com/dart-lang/linter/issues/5045
await assertDiagnostics(
r'''
// @dart=3.12
void f(final int _) {}
''',
[lint(7, 5)],
[lint(21, 5)],
);
}
test_setter_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
set f(final int value) {}
''',
[lint(6, 5)],
[lint(20, 5)],
);
}
test_setter_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
set f(int value) {}
''');
}
@@ -398,6 +433,7 @@ set f(int value) {}
test_super_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
class A {
String? a;
String? b;
@@ -408,14 +444,15 @@ class B extends A {
}
''',
[
error(diag.unnecessaryFinal, 83, 5),
error(diag.unnecessaryFinal, 98, 5),
error(diag.unnecessaryFinal, 97, 5),
error(diag.unnecessaryFinal, 112, 5),
],
);
}
test_super_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class A {
String? a;
String? b;
@@ -430,34 +467,38 @@ class B extends A {
test_typedef_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
typedef String Type(final value);
''',
[lint(20, 5)],
[lint(34, 5)],
);
}
test_typedef_genericFunctionType_final() async {
await assertDiagnostics(
r'''
// @dart=3.12
typedef F = void Function(final x);
''',
[
// No lint reported to avoid redundancy with
// `functionTypedParameterVar`.
error(diag.functionTypedParameterVar, 26, 5),
error(diag.undefinedClass, 32, 1),
error(diag.functionTypedParameterVar, 40, 5),
error(diag.undefinedClass, 46, 1),
],
);
}
test_typedef_genericFunctionType_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
typedef F = void Function(int x);
''');
}
test_typedef_noFinal() async {
await assertNoDiagnostics(r'''
// @dart=3.12
typedef String Type(int value);
''');
}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -18,18 +17,12 @@ void main() {
@reflectiveTest
class PreferFinalParametersBeforePrimaryConstructorsTest extends LintRuleTest {
@override
List<String> get experiments => super.experiments
.where(
(experiment) => experiment != Feature.primary_constructors.enableString,
)
.toList();
@override
String get lintRule => LintNames.prefer_final_parameters;
test_blockBody_reassigned() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(String p) {
p = 'Lint away!';
}
@@ -39,16 +32,18 @@ void f(String p) {
test_closure() async {
await assertDiagnostics(
r'''
// @dart=3.12
var f = (Object p) {
print(p);
};
''',
[lint(9, 8)],
[lint(23, 8)],
);
}
test_closure_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(final List<int> x) {
x.forEach((final int e) => print(e + 4));
}
@@ -57,6 +52,7 @@ void f(final List<int> x) {
test_closure_final_untyped() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(final List<int> x) {
x.forEach((final e) => print(e + 4));
}
@@ -66,22 +62,25 @@ void f(final List<int> x) {
test_closure_untyped() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(final List<int> x) {
x.forEach((e) => print(e + 4));
}
''',
[lint(41, 1)],
[lint(55, 1)],
);
}
test_closure_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
var f = (Object _) { };
''');
}
test_constructor_unused_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
C(String _);
}
@@ -91,6 +90,7 @@ class C {
test_constructor_usedInBody() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int x = 0;
C(String p) {
@@ -98,24 +98,26 @@ class C {
}
}
''',
[lint(27, 8)],
[lint(41, 8)],
);
}
test_constructor_usedInInitializer() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
String x = '';
C(String x): this.x = x;
}
''',
[lint(31, 8)],
[lint(45, 8)],
);
}
test_constructor_usedInInitializer_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int x = 0;
C(final int x): x = x;
@@ -125,12 +127,14 @@ class C {
test_expressionBody_reassigned() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int p) => p = 3;
''');
}
test_getter() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int _f = 0;
int get f => _f;
@@ -140,6 +144,7 @@ class C {
test_initializingFormal_named() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
String f;
C({required this.f});
@@ -149,6 +154,7 @@ class C {
test_initializingFormal_positional() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
String f;
C(this.f);
@@ -158,6 +164,7 @@ class C {
test_listPattern_destructured() async {
await assertNoDiagnostics('''
// @dart=3.12
void f(int p) {
[_, p, _] = [1, 2, 3];
}
@@ -167,18 +174,20 @@ void f(int p) {
test_method() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
void m(String p) {
print(p);
}
}
''',
[lint(19, 8)],
[lint(33, 8)],
);
}
test_method_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
void m(final String p) {
print(p);
@@ -189,6 +198,7 @@ class C {
test_method_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
void m(String _) { }
}
@@ -197,6 +207,7 @@ class C {
test_method_wildcard_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
void m(final String _) { }
}
@@ -206,18 +217,20 @@ class C {
test_operator() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
C operator +(C other) {
return other;
}
}
''',
[lint(25, 7)],
[lint(39, 7)],
);
}
test_operator_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
C operator +(final C other) {
return other;
@@ -238,6 +251,7 @@ class C {
test_recordPattern_destructured() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int a, int b) {
(a, b) = (1, 2);
}
@@ -247,17 +261,19 @@ void f(int a, int b) {
test_setter() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int x = 0;
void set f(int y) => x = y;
}
''',
[lint(36, 5)],
[lint(50, 5)],
);
}
test_setter_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int x = 0;
void set f(final int y) => x = y;
@@ -267,6 +283,7 @@ class C {
test_setter_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
void set f(int _) { }
}
@@ -275,6 +292,7 @@ class C {
test_superParameter() async {
await assertNoDiagnostics('''
// @dart=3.12
class D {
D(final int superParameter);
}
@@ -287,6 +305,7 @@ class E extends D {
test_superParameter_optional() async {
await assertNoDiagnostics('''
// @dart=3.12
class A {
final String? a;
A({this.a});
@@ -301,20 +320,23 @@ class B extends A {
test_topLevelFunction() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(int p) => print(p);
''',
[lint(7, 5)],
[lint(21, 5)],
);
}
test_topLevelFunction_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(final int p) => print(p);
''');
}
test_topLevelFunction_final_multiple() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(final String p, final String p2) {
print(p);
print(p2);
@@ -325,16 +347,18 @@ void f(final String p, final String p2) {
test_topLevelFunction_named() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({String? p}) {
print(p);
}
''',
[lint(8, 9)],
[lint(22, 9)],
);
}
test_topLevelFunction_named_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({final String? p}) {
print(p);
}
@@ -344,12 +368,13 @@ void f({final String? p}) {
test_topLevelFunction_named_wildcard() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({final String? _}) { }
''',
[
// No lint.
// https://github.com/dart-lang/language/blob/main/working/wildcards/feature-specification.md#declarations-that-are-capable-of-declaring-a-wildcard
error(diag.privateNamedNonFieldParameter, 22, 1),
error(diag.privateNamedNonFieldParameter, 36, 1),
],
);
}
@@ -357,16 +382,18 @@ void f({final String? _}) { }
test_topLevelFunction_namedRequired() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({required String p}) {
print(p);
}
''',
[lint(8, 17)],
[lint(22, 17)],
);
}
test_topLevelFunction_namedRequired_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({required final String p}) {
print(p);
}
@@ -376,12 +403,13 @@ void f({required final String p}) {
test_topLevelFunction_namedRequired_wildcard() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({required String _}) { }
''',
[
// No lint.
// https://github.com/dart-lang/language/blob/main/working/wildcards/feature-specification.md#declarations-that-are-capable-of-declaring-a-wildcard
error(diag.privateNamedNonFieldParameter, 24, 1),
error(diag.privateNamedNonFieldParameter, 38, 1),
],
);
}
@@ -389,16 +417,18 @@ void f({required String _}) { }
test_topLevelFunction_optional() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f([String? p]) {
print(p);
}
''',
[lint(8, 9)],
[lint(22, 9)],
);
}
test_topLevelFunction_optional_final() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([final String? p]) {
print(p);
}
@@ -407,12 +437,14 @@ void f([final String? p]) {
test_topLevelFunction_optional_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([String? _]) { }
''');
}
test_topLevelFunction_wildcard() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int _){ }
''');
}
@@ -212,7 +212,7 @@ class C(final int x);
[
error(diag.experimentNotEnabled, 23, 1),
lint(24, 5),
error(diag.experimentNotEnabledOffByDefault, 36, 1),
error(diag.experimentNotEnabled, 36, 1),
],
);
}
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -17,16 +16,12 @@ void main() {
@reflectiveTest
class VarWithNoTypeAnnotationPrePrimaryConstructorsTest extends LintRuleTest {
@override
List<String> get experiments => super.experiments
.where((e) => e != Feature.primary_constructors.enableString)
.toList();
@override
String get lintRule => LintNames.var_with_no_type_annotation;
test_constructorFieldFormal_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int p;
C(this.p);
@@ -37,17 +32,19 @@ class C {
test_constructorFieldFormal_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int p;
C(var this.p);
}
''',
[lint(23, 3)],
[lint(37, 3)],
);
}
test_constructorSimple_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
C(int p);
}
@@ -57,16 +54,18 @@ class C {
test_constructorSimple_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
C(var p);
}
''',
[lint(14, 3)],
[lint(28, 3)],
);
}
test_extension_method_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
extension E on int {
void f(int p) {}
}
@@ -76,16 +75,18 @@ extension E on int {
test_extension_method_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
extension E on int {
void f(var p) {}
}
''',
[lint(30, 3)],
[lint(44, 3)],
);
}
test_extensionType_method_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
extension type E(int i) {
void f(int p) {}
}
@@ -95,16 +96,18 @@ extension type E(int i) {
test_extensionType_method_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
extension type E(int i) {
void f(var p) {}
}
''',
[lint(35, 3)],
[lint(49, 3)],
);
}
test_functionExpression_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
var f = (int value) {};
''');
}
@@ -112,14 +115,16 @@ var f = (int value) {};
test_functionExpression_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
var f = (var value) {};
''',
[lint(9, 3)],
[lint(23, 3)],
);
}
test_functionTyped_fieldFormal_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
final void Function(int) f;
C(void this.f(int p));
@@ -130,17 +135,19 @@ class C {
test_functionTyped_fieldFormal_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
final void Function(int) f;
C(void this.f(var p));
}
''',
[lint(56, 3)],
[lint(70, 3)],
);
}
test_functionTyped_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int p()) {}
''');
}
@@ -148,14 +155,16 @@ void f(int p()) {}
test_functionTyped_parameter_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(void g(var p)) {}
''',
[lint(14, 3)],
[lint(28, 3)],
);
}
test_functionTyped_superFormal_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class A {
A(void f(int p));
}
@@ -168,6 +177,7 @@ class B extends A {
test_functionTyped_superFormal_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class A {
A(void f(int p));
}
@@ -175,21 +185,23 @@ class B extends A {
B(void super.f(var p));
}
''',
[lint(69, 3)],
[lint(83, 3)],
);
}
test_functionTyped_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(var p()) {}
''',
[error(diag.functionTypedParameterVar, 7, 3)],
[error(diag.functionTypedParameterVar, 21, 3)],
);
}
test_functionTypedParameter_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(void g(int p)) {}
''');
}
@@ -197,16 +209,18 @@ void f(void g(int p)) {}
test_localFunction_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f() {
void g(var p) {}
}
''',
[lint(20, 3)],
[lint(34, 3)],
);
}
test_mixin_method_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
mixin M {
void f(int p) {}
}
@@ -216,16 +230,18 @@ mixin M {
test_mixin_method_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
mixin M {
void f(var p) {}
}
''',
[lint(19, 3)],
[lint(33, 3)],
);
}
test_operator_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class C {
int operator +(int other) => 0;
}
@@ -235,16 +251,18 @@ class C {
test_operator_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
int operator +(var other) => 0;
}
''',
[lint(27, 3)],
[lint(41, 3)],
);
}
test_optionalNamed_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({int? p}) {}
''');
}
@@ -252,14 +270,16 @@ void f({int? p}) {}
test_optionalNamed_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({var p}) {}
''',
[lint(8, 3)],
[lint(22, 3)],
);
}
test_optionalPositional_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([int? p]) {}
''');
}
@@ -267,14 +287,16 @@ void f([int? p]) {}
test_optionalPositional_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f([var p]) {}
''',
[lint(8, 3)],
[lint(22, 3)],
);
}
test_optionalPositionalWithDefault_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f([int p = 0]) {}
''');
}
@@ -282,14 +304,16 @@ void f([int p = 0]) {}
test_optionalPositionalWithDefault_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f([var p = 0]) {}
''',
[lint(8, 3)],
[lint(22, 3)],
);
}
test_requiredNamed_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f({required int p}) {}
''');
}
@@ -297,14 +321,16 @@ void f({required int p}) {}
test_requiredNamed_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f({required var p}) {}
''',
[lint(17, 3)],
[lint(31, 3)],
);
}
test_requiredPositional_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
void f(int p) {}
''');
}
@@ -312,23 +338,26 @@ void f(int p) {}
test_requiredPositional_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(var p) {}
''',
[lint(7, 3)],
[lint(21, 3)],
);
}
test_requiredPositional_wildcard() async {
await assertDiagnostics(
r'''
// @dart=3.12
void f(var _) {}
''',
[lint(7, 3)],
[lint(21, 3)],
);
}
test_setter_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
set f(int value) {}
''');
}
@@ -336,14 +365,16 @@ set f(int value) {}
test_setter_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
set f(var value) {}
''',
[lint(6, 3)],
[lint(20, 3)],
);
}
test_super_noVar() async {
await assertNoDiagnostics(r'''
// @dart=3.12
class A {
String? a;
A(this.a);
@@ -357,6 +388,7 @@ class B extends A {
test_super_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
class A {
String? a;
A(this.a);
@@ -365,19 +397,20 @@ class B extends A {
B(var super.a);
}
''',
[error(diag.extraneousModifier, 62, 3)],
[error(diag.extraneousModifier, 76, 3)],
);
}
test_typedef_genericFunctionType_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
typedef F = void Function(var x);
''',
[
error(diag.functionTypedParameterVar, 26, 3),
error(diag.varAndType, 26, 3),
error(diag.undefinedClass, 30, 1),
error(diag.functionTypedParameterVar, 40, 3),
error(diag.varAndType, 40, 3),
error(diag.undefinedClass, 44, 1),
],
);
}
@@ -385,20 +418,22 @@ typedef F = void Function(var x);
test_typedef_var() async {
await assertDiagnostics(
r'''
// @dart=3.12
typedef String Type(var value);
''',
[lint(20, 3)],
[lint(34, 3)],
);
}
test_var_type() async {
await assertDiagnostics(
r'''
// @dart=3.12
class C {
C(var int p);
}
''',
[error(diag.varAndType, 14, 3)],
[error(diag.varAndType, 28, 3)],
);
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ TEST_CASE(StackMapGC) {
const char* kScriptChars = R"(
class A {
@pragma("vm:external-name", "NativeFunc")
external static void func(var i, var k);
external static void func(i, k);
static foo() {
var i;
var s1;
+1 -1
View File
@@ -54,7 +54,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_EliminateWriteBarrier) {
// clang-format off
const char* kScript = R"(
class Container<T> {
operator []=(var index, var value) {
operator []=(index, value) {
return data[index] = value;
}
+14 -14
View File
@@ -3007,12 +3007,12 @@ static void TestTypedDataDirectAccess1() {
" }\n"
" }\n"
"}\n"
"void setMain(var a) {"
"void setMain(a) {"
" for (var i = 0; i < 10; i++) {"
" a[i] = i;"
" }"
"}\n"
"bool testMain(var list) {"
"bool testMain(list) {"
" for (var i = 0; i < 10; i++) {"
" Expect.equals((10 + i), list[i]);"
" }\n"
@@ -3076,13 +3076,13 @@ static void TestTypedDataViewDirectAccess() {
" }\n"
" }\n"
"}\n"
"void setMain(var list) {"
"void setMain(list) {"
" Expect.equals(10, list.length);"
" for (var i = 0; i < 10; i++) {"
" list[i] = i;"
" }"
"}\n"
"bool testMain(var list) {"
"bool testMain(list) {"
" Expect.equals(10, list.length);"
" for (var i = 0; i < 10; i++) {"
" Expect.equals((10 + i), list[i]);"
@@ -3177,13 +3177,13 @@ static void TestByteDataDirectAccess() {
" }\n"
" }\n"
"}\n"
"void setMain(var list) {"
"void setMain(list) {"
" Expect.equals(10, list.length);"
" for (var i = 0; i < 10; i++) {"
" list.setInt8(i, i);"
" }"
"}\n"
"bool testMain(var list) {"
"bool testMain(list) {"
" Expect.equals(10, list.length);"
" for (var i = 0; i < 10; i++) {"
" Expect.equals((10 + i), list.getInt8(i));"
@@ -5601,16 +5601,16 @@ TEST_CASE(DartAPI_FieldAccess) {
" static const _const_static_fld = 'hidden const static';\n"
"\n"
" get instance_getset_fld { return _gs_fld1; }\n"
" void set instance_getset_fld(var value) { _gs_fld1 = value; }\n"
" void set instance_getset_fld(value) { _gs_fld1 = value; }\n"
" get _instance_getset_fld { return _gs_fld2; }\n"
" void set _instance_getset_fld(var value) { _gs_fld2 = value; }\n"
" void set _instance_getset_fld(value) { _gs_fld2 = value; }\n"
" var _gs_fld1;\n"
" var _gs_fld2;\n"
"\n"
" static get static_getset_fld { return _gs_fld3; }\n"
" static void set static_getset_fld(var value) { _gs_fld3 = value; }\n"
" static void set static_getset_fld(value) { _gs_fld3 = value; }\n"
" static get _static_getset_fld { return _gs_fld4; }\n"
" static void set _static_getset_fld(var value) { _gs_fld4 = value; }\n"
" static void set _static_getset_fld(value) { _gs_fld4 = value; }\n"
" static var _gs_fld3;\n"
" static var _gs_fld4;\n"
"}\n"
@@ -5620,9 +5620,9 @@ TEST_CASE(DartAPI_FieldAccess) {
"const _const_top_fld = 'hidden const top';\n"
"\n"
"get top_getset_fld { return _gs_fld5; }\n"
"void set top_getset_fld(var value) { _gs_fld5 = value; }\n"
"void set top_getset_fld(value) { _gs_fld5 = value; }\n"
"get _top_getset_fld { return _gs_fld6; }\n"
"void set _top_getset_fld(var value) { _gs_fld6 = value; }\n"
"void set _top_getset_fld(value) { _gs_fld6 = value; }\n"
"var _gs_fld5;\n"
"var _gs_fld6;\n"
"\n"
@@ -5639,9 +5639,9 @@ TEST_CASE(DartAPI_FieldAccess) {
"var imported_fld = 'imported';\n"
"var _imported_fld = 'hidden imported';\n"
"get imported_getset_fld { return _gs_fld1; }\n"
"void set imported_getset_fld(var value) { _gs_fld1 = value; }\n"
"void set imported_getset_fld(value) { _gs_fld1 = value; }\n"
"get _imported_getset_fld { return _gs_fld2; }\n"
"void set _imported_getset_fld(var value) { _gs_fld2 = value; }\n"
"void set _imported_getset_fld(value) { _gs_fld2 = value; }\n"
"var _gs_fld1;\n"
"var _gs_fld2;\n"
"void test2() {\n"
+1 -1
View File
@@ -90,7 +90,7 @@ TEST_CASE(UnhandledExceptions) {
R"(
class UnhandledExceptions {
@pragma('vm:external-name', 'Unhandled_equals')
external static equals(var obj1, var obj2);
external static equals(obj1, obj2);
@pragma('vm:external-name', 'Unhandled_invoke')
external static invoke();
+2 -1
View File
@@ -18,7 +18,7 @@ bool GetExperimentalFeatureDefault(ExperimentalFeature feature) {
constexpr bool kFeatureValues[] = {
true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true,
};
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureValues));
return kFeatureValues[static_cast<int>(feature)];
@@ -26,6 +26,7 @@ bool GetExperimentalFeatureDefault(ExperimentalFeature feature) {
const char* GetExperimentalFeatureName(ExperimentalFeature feature) {
constexpr const char* kFeatureNames[] = {
"primary-constructors",
"private-named-parameters",
"dot-shorthands",
"native-assets",
+1
View File
@@ -12,6 +12,7 @@
namespace dart {
enum class ExperimentalFeature {
primary_constructors,
private_named_parameters,
dot_shorthands,
native_assets,
+1 -1
View File
@@ -3360,7 +3360,7 @@ TEST_CASE(StackTraceFormat) {
" }\n"
"}\n"
"\n"
"set globalVar(var value) {\n"
"set globalVar(value) {\n"
" new _OtherClass._named();\n"
"}\n"
"\n"
+2 -2
View File
@@ -163,7 +163,7 @@ TEST_CASE(ValidateStackFrameIteration) {
const char* kScriptChars =
"class StackFrame {"
" @pragma('vm:external-name', 'StackFrame_equals')\n"
" external static equals(var obj1, var obj2);\n"
" external static equals(obj1, obj2);\n"
" @pragma('vm:external-name', 'StackFrame_frameCount')\n"
" external static int frameCount();\n"
" @pragma('vm:external-name', 'StackFrame_dartFrameCount')\n"
@@ -255,7 +255,7 @@ TEST_CASE(ValidateNoSuchMethodStackFrameIteration) {
const char* const kScriptChars =
"class StackFrame {"
" @pragma('vm:external-name', 'StackFrame_equals')\n"
" external static equals(var obj1, var obj2);\n"
" external static equals(obj1, obj2);\n"
" @pragma('vm:external-name', 'StackFrame_frameCount')\n"
" external static int frameCount();\n"
" @pragma('vm:external-name', 'StackFrame_dartFrameCount')\n"
@@ -346,7 +346,7 @@ enum ConflictConstructorNameStaticEnumValue {
enum ConflictClassStatic {
e1;
//^
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
// [cfe] A const constructor can't have a body.
static int ConflictClassStatic() => 37;
//^^^^^^
// [analyzer] SYNTACTIC_ERROR.STATIC_CONSTRUCTOR
@@ -354,11 +354,11 @@ enum ConflictClassStatic {
// ^^^
// [analyzer] SYNTACTIC_ERROR.CONSTRUCTOR_WITH_RETURN_TYPE
// [cfe] Constructors can't have a return type.
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR
// [cfe] Generative enum constructors must be marked as 'const'.
// ^^
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATIVE_CONSTRUCTOR
// [cfe] A generative enum constructor can't have a body.
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] Constructors can't have a return type.
@@ -367,16 +367,16 @@ enum ConflictClassStatic {
enum ConflictClassInstance {
e1;
//^
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
// [cfe] A const constructor can't have a body.
int ConflictClassInstance() => 37;
//^^^
// [analyzer] SYNTACTIC_ERROR.CONSTRUCTOR_WITH_RETURN_TYPE
// [cfe] Constructors can't have a return type.
// ^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR
// [cfe] Generative enum constructors must be marked as 'const'.
// ^^
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_IN_GENERATIVE_CONSTRUCTOR
// [cfe] A generative enum constructor can't have a body.
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] Constructors can't have a return type.
@@ -489,11 +489,8 @@ enum NoConstructorCalls {
// [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT
// [cfe] Enums can't be instantiated.
// Generative constructors must be const.
// Generative constructors are implicitly const.
NoConstructorCalls.notConst(this.x);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR
// [cfe] Generative enum constructors must be marked as 'const'.
// As usual, redirecting generative constructors must redirect to
// generative constructors.
@@ -25,5 +25,5 @@ extension type ET3(num id) {
extension type ET4(covariant num id) {}
// ^^^^^^^^^
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER_IN_PRIMARY_CONSTRUCTOR
// [cfe] Can't have modifier 'covariant' in a primary constructor.
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
@@ -12,9 +12,6 @@ abstract class I implements S;
// ^
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION
// [cfe] 'I' is already declared in this scope.
// ^
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED_OFF_BY_DEFAULT
// [cfe] This requires the experimental 'primary-constructors' language feature to be enabled.
class C implements I { }
@@ -12,9 +12,6 @@ class C implements S;
// ^
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION
// [cfe] 'C' is already declared in this scope.
// ^
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED_OFF_BY_DEFAULT
// [cfe] This requires the experimental 'primary-constructors' language feature to be enabled.
main() {
Expect.isFalse(new C() is S);
@@ -2,11 +2,20 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Declaring constructors are not enabled in versions before release.
// Primary constructors are not enabled in versions before release.
// @dart=3.9
// @dart=3.12
class Point(var int x, var int y);
// ^
// [analyzer] unspecified
// [cfe] unspecified
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] The 'primary-constructors' language feature is disabled for this library.
// ^^^
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] The 'primary-constructors' language feature is disabled for this library.
// ^^^
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] The 'primary-constructors' language feature is disabled for this library.
// ^
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] The 'primary-constructors' language feature is disabled for this library.
@@ -1,10 +0,0 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Declaring constructors are not enabled by default.
class Point(var int x, var int y);
// ^
// [analyzer] unspecified
// [cfe] unspecified
@@ -0,0 +1,15 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Primary constructors are enabled by default.
import 'package:expect/expect.dart';
class Point(var int x, var int y);
void main() {
var p = Point(1, 2);
Expect.equals(p.x, 1);
Expect.equals(p.y, 2);
}
+1 -1
View File
@@ -12,7 +12,7 @@ set tooFew() {}
// ^
// [cfe] A setter should have exactly one formal parameter.
set tooMany(value, var extra) {}
set tooMany(value, int extra) {}
// ^^^^^^^
// [analyzer] SYNTACTIC_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// ^
@@ -19,14 +19,13 @@ class Class<T> {
Class.private(this._privateField);
Class.explicitType(num this.numField);
Class.withVar(var this.numField);
Class.withNoType(this.numField);
Class.withSubtype(int this.numField);
}
class Constant {
final num value;
const Constant(this.value);
const Constant.marked(final this.value);
}
void main() {
@@ -107,7 +106,7 @@ void main() {
Expect.isFalse(pm.isStatic);
Expect.isFalse(pm.isTopLevel);
mm = reflectClass(Class).declarations[#Class.withVar] as MethodMirror;
mm = reflectClass(Class).declarations[#Class.withNoType] as MethodMirror;
pm = mm.parameters.single;
Expect.equals(#numField, pm.simpleName);
Expect.equals(reflectClass(num), pm.type);
@@ -142,16 +141,4 @@ void main() {
Expect.isFalse(pm.isPrivate);
Expect.isFalse(pm.isStatic);
Expect.isFalse(pm.isTopLevel);
mm = reflectClass(Constant).declarations[#Constant.marked] as MethodMirror;
pm = mm.parameters.single;
Expect.equals(#value, pm.simpleName);
Expect.equals(reflectClass(num), pm.type);
Expect.isFalse(pm.isNamed);
Expect.isTrue(pm.isFinal); // N.B.
Expect.isFalse(pm.isOptional);
Expect.isFalse(pm.hasDefaultValue);
Expect.isFalse(pm.isPrivate);
Expect.isFalse(pm.isStatic);
Expect.isFalse(pm.isTopLevel);
}
+1 -1
View File
@@ -12,7 +12,7 @@ main() {
import 'dart:io';
class Expect {
static void isTrue(var x) {
static void isTrue(x) {
if (!identical(x, true)) {
throw new StateError("Not identical");
}
+10 -4
View File
@@ -164,10 +164,6 @@ features:
static-extensions:
help: "Extensions with static capabilities."
primary-constructors:
help: "Less verbose constructors."
experimentalReleaseVersion: '3.12.0'
anonymous-methods:
help: "Anonymous methods."
# TODO(eernst): Enable this when the feature is implemented.
@@ -188,6 +184,16 @@ features:
#
# Shipped flags should be marked retired the following stable release.
#
primary-constructors:
enabledIn: '3.13.0'
help: "Less verbose constructors."
experimentalReleaseVersion: '3.12.0'
validation: |
class C(var String x);
main() {
print(C('feature enabled').x);
}
private-named-parameters:
enabledIn: '3.12.0'
help: "Allow named parameters with private names that refer to fields."