[tests] Primary constructors: Format and generate errors for all tests.
Cleaned up and formatted the tests, regenerated some errors where they were "unspecified", and removed the experiment flag enabling in each test. Bug: https://github.com/dart-lang/sdk/issues/61687 Change-Id: Ic5b652af660cbc4f71731b1547c7a58c7726faca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503500 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
committed by
dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
a93e065e54
commit
2edcad4892
@@ -5,8 +5,6 @@
|
||||
// A compile-time error occurs if an assignment to a primary parameter occurs
|
||||
// in the initializing expression of a non-late instance variable.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(int x, Object? z) {
|
||||
Record y = (
|
||||
++x,
|
||||
|
||||
@@ -12,18 +12,14 @@
|
||||
// the initializer list contains an expression which is not potentially
|
||||
// constant.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
int fn(int x) => x;
|
||||
|
||||
class const C(int p) {
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
|
||||
// TODO(cfe): Avoid having multiple errors here and make sure the error
|
||||
// message is accurate. i.e. "Not a potentially constant expression."
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
|
||||
final int x = fn(p);
|
||||
// ^
|
||||
// [cfe] unspecified
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
}
|
||||
|
||||
class const C2(int p) {
|
||||
@@ -35,14 +31,14 @@ class const C2(int p) {
|
||||
}
|
||||
|
||||
enum const E(int p) {
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST
|
||||
e(1);
|
||||
|
||||
final int x = fn(p);
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_METHOD_INVOCATION
|
||||
// [cfe] Static invocation is not a constant expression.
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
}
|
||||
|
||||
extension type const Ext(int p) {
|
||||
@@ -58,14 +54,13 @@ extension type const Ext(int p) {
|
||||
// constant.
|
||||
|
||||
class const A(dynamic d) {
|
||||
// TODO(cfe): Avoid having multiple errors here and make sure the error
|
||||
// message is accurate. i.e. "Not a potentially constant expression."
|
||||
final int i = d.length;
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_PROPERTY_ACCESS
|
||||
// [cfe] unspecified
|
||||
}
|
||||
|
||||
void main() {
|
||||
const A([]); // Error because `[].length` isn't constant.
|
||||
// ^
|
||||
// [cfe] Constant evaluation error:
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
// primary constructor, or in an initializing expression of a non-late instance
|
||||
// variable declaration, is potentially constant.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class const A(dynamic d) {
|
||||
|
||||
@@ -2,8 +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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// Tests cycle errors for primary constructors.
|
||||
|
||||
class A() extends C {}
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
// initializer list of the body part, or by an initializing formal parameter
|
||||
// of the primary constructor.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1(this.x) {
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZED_IN_DECLARATION_AND_PARAMETER_OF_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Fields can't be initialized in both the primary constructor parameter list and at their declaration.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZED_IN_DECLARATION_AND_PARAMETER_OF_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Fields can't be initialized in both the primary constructor parameter list and at their declaration.
|
||||
int x = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// the instance variable declaration which is induced by this declaring
|
||||
// constructor parameter is `final`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(final int x);
|
||||
|
||||
class D(var int x);
|
||||
@@ -22,4 +20,3 @@ void main() {
|
||||
var d = D(1);
|
||||
d.x = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// primary constructor whose name is also the name of a constructor declared
|
||||
// in the body.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1(final int x) {
|
||||
C1(this.x);
|
||||
// [error column 3, length 2]
|
||||
@@ -26,6 +24,7 @@ class C2.named(final int x) {
|
||||
|
||||
enum E1(final int x) {
|
||||
e(1);
|
||||
|
||||
const E1(this.x);
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_CONSTRUCTOR
|
||||
@@ -38,6 +37,7 @@ enum E2.named(final int x) {
|
||||
// [error column 3, length 1]
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ENUM_CONSTRUCTOR
|
||||
// [cfe] Couldn't find constructor 'E2'.
|
||||
|
||||
const E2.named(this.x);
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_CONSTRUCTOR
|
||||
|
||||
@@ -4,20 +4,18 @@
|
||||
|
||||
// An enum cannot declare mutable fields through declaring parameters.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
enum E1(var int x) {
|
||||
// ^
|
||||
// [cfe] Enum constructors are constant so all fields must be final.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_FINAL_FIELD_IN_ENUM
|
||||
// ^
|
||||
// [cfe] Enum constructors are constant so all fields must be final.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_FINAL_FIELD_IN_ENUM
|
||||
|
||||
a(0)
|
||||
}
|
||||
|
||||
enum E2() {
|
||||
// ^
|
||||
// [cfe] Enum constructors are constant so all fields must be final.
|
||||
// ^
|
||||
// [cfe] Enum constructors are constant so all fields must be final.
|
||||
a;
|
||||
|
||||
int x = 0;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// Extension types are allowed to have non-redirecting generative constructors,
|
||||
// implicitly or explicitly initializing the representation variable.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
extension type ET1(int x) {
|
||||
|
||||
@@ -8,38 +8,41 @@
|
||||
// declaration must still have exactly one parameter, which must be declaring.
|
||||
// The `final` can be omitted, but a `var` cannot be used.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// -----------------
|
||||
// No `var` allowed.
|
||||
|
||||
extension type ET1(var int i);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// ^
|
||||
// [cfe] Representation fields can't have modifiers.
|
||||
|
||||
extension type ET2(var i);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// ^
|
||||
// [cfe] Representation fields can't have modifiers.
|
||||
|
||||
// --------------------------------
|
||||
// Must have exactly one parameter.
|
||||
|
||||
extension type ET3(final i, final x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [cfe] Each extension type should have exactly one representation field.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
|
||||
|
||||
extension type ET4(int i, int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [cfe] Each extension type should have exactly one representation field.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
|
||||
|
||||
extension type ET5(int i, final x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [cfe] Each extension type should have exactly one representation field.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
|
||||
|
||||
// --------------------
|
||||
// The extension type representation parameter cannot be covariant.
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// primary constructor can be specified or omitted.
|
||||
// So can type, in which case the representation type is `Object?`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:expect/static_type_helper.dart';
|
||||
|
||||
|
||||
+25
-26
@@ -5,59 +5,58 @@
|
||||
// A class that has a declaring header constructor cannot have any other
|
||||
// non-redirecting generative constructors.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1(var int x) {
|
||||
C1.named(this.x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 8]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C2(final int x) {
|
||||
C2.named(this.x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 8]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C3(int x) {
|
||||
C3.named(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 8]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C4() {
|
||||
C4.named(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 8]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C5.named(var int x) {
|
||||
C5(this.x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 2]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C6.named(final int x) {
|
||||
C6(this.x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 2]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C7.named(int x) {
|
||||
C7(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 2]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
class C8.named() {
|
||||
C8(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 2]
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_REDIRECTING_GENERATIVE_CONSTRUCTOR_WITH_PRIMARY
|
||||
// [cfe] Classes with primary constructors can't have non-redirecting generative constructors.
|
||||
}
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
// A class that has a declaring header constructor can have redirecting
|
||||
// generative constructors and factory constructors.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class C1(final int x) {
|
||||
C1.redirecting(int x): this(x);
|
||||
C1.redirecting(int x) : this(x);
|
||||
}
|
||||
|
||||
class C2.named(final int x) {
|
||||
C2.redirecting(int x): this.named(x);
|
||||
C2.redirecting(int x) : this.named(x);
|
||||
}
|
||||
|
||||
class C3(final int x) {
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// These elements are placed in the class body in a declaration that provides
|
||||
// "the rest" of the constructor declaration which is given in the header.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class C1(final int x) {
|
||||
|
||||
+7
-8
@@ -2,21 +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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// Tests that declaring constructors with optional parameters cannot have
|
||||
// non-constant default values in a header declaring constructor.
|
||||
|
||||
int f() => 0;
|
||||
|
||||
class C([int x = f()]);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_METHOD_INVOCATION
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
|
||||
|
||||
enum E([int x = f()]) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_METHOD_INVOCATION
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
e;
|
||||
}
|
||||
|
||||
@@ -5,29 +5,27 @@
|
||||
// Formal parameter types of primary constructor are resolved within the body
|
||||
// scope of the enclosing declaration.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(int x) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] 'int' isn't a type.
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_A_TYPE
|
||||
// [cfe] 'int' isn't a type.
|
||||
|
||||
static const String int = 'not a type';
|
||||
}
|
||||
|
||||
enum E(int x) {
|
||||
// ^
|
||||
// [cfe] 'int' isn't a type.
|
||||
// [analyzer] unspecified
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_A_TYPE
|
||||
// [cfe] 'int' isn't a type.
|
||||
a(0);
|
||||
|
||||
static const String int = 'not a type';
|
||||
}
|
||||
|
||||
extension type ET(int x) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] 'int' isn't a type.
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_A_TYPE
|
||||
// [cfe] 'int' isn't a type.
|
||||
|
||||
static const String int = 'not a type';
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
// primary constructor were not resolved within the body scope of the
|
||||
// enclosing declaration.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
extension type ET(int x) {
|
||||
static const String int = 'not a type';
|
||||
}
|
||||
|
||||
@@ -6,60 +6,59 @@
|
||||
// declares a primary constructor whose name is `C.n`, and the body declares a
|
||||
// static member whose basename is `n`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static int name = 1;
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'C1.name'.
|
||||
}
|
||||
|
||||
class C2.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static int get name => 1;
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'C2.name'.
|
||||
}
|
||||
|
||||
class C3.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static void set name(int x) {}
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'C3.name'.
|
||||
}
|
||||
|
||||
class C4.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static void name() {}
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'C4.name'.
|
||||
}
|
||||
|
||||
mixin class M1.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static int name = 1;
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'M1.name'.
|
||||
}
|
||||
|
||||
enum E1.name() {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
e.name();
|
||||
|
||||
static int name = 1;
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'E1.name'.
|
||||
}
|
||||
|
||||
extension type ET1.name(int x) {
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
|
||||
static int name = 1;
|
||||
// ^
|
||||
// [cfe] The member conflicts with constructor 'ET1.name'.
|
||||
|
||||
+10
-12
@@ -2,26 +2,24 @@
|
||||
// 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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// Late variables cannot access primary constructor parameters.
|
||||
class LateError(int x) {
|
||||
late int y = x;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] The getter 'x' isn't defined for the type 'LateError'.
|
||||
}
|
||||
|
||||
// In non-primary constructors, the parameter `x` is not in scope.
|
||||
class NotPrimaryConstructor {
|
||||
int y = x;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] Undefined name 'x'.
|
||||
int z = x + 1;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] Undefined name 'x'.
|
||||
NotPrimaryConstructor(int x);
|
||||
}
|
||||
|
||||
@@ -30,8 +28,8 @@ class NotPrimaryConstructor {
|
||||
class AssignToParameter(int x) {
|
||||
int y = x++;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_PRIMARY_CONSTRUCTOR_PARAMETER
|
||||
// [cfe] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
|
||||
// A compile-time error occurs if an assignment to a primary parameter occurs
|
||||
@@ -40,6 +38,6 @@ class AssignToParameterInitializer(int x) {
|
||||
final int y;
|
||||
this : y = x++;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_PRIMARY_CONSTRUCTOR_PARAMETER
|
||||
// [cfe] A primary constructor parameter can't be assigned to in an initializer.
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
// It is also the current scope for the initializer list in the body part of the
|
||||
// primary constructor, if any.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class InitializingExpression(int x) {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// The body of a primary constructor does not have access to declaring
|
||||
// parameters, initializing formals, or super parameters.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
int k = 42;
|
||||
|
||||
class A {
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// Instance variables are accessable in this scope, but not any declaring
|
||||
// parameters, super parameters, or initializing formals.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C1(var int x) {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// `factory() => C();` is a factory constructor whose name is the name of the
|
||||
// enclosing class, and not a method.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C {
|
||||
final int x;
|
||||
C.named(this.x);
|
||||
@@ -16,7 +14,7 @@ class C {
|
||||
void main() {
|
||||
var c = C.named(1);
|
||||
c.factory();
|
||||
//^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
//^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
|
||||
// [cfe] The method 'factory' isn't defined for the type 'C'.
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// Using `factory name()` to declare named factory constructors with new shorter
|
||||
// syntax.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C1 {
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
// declaration has some of the keywords external and augment, but we don't
|
||||
// test those kinds of constructors here.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// `factory() => C();` is a factory constructor whose name is the name of the
|
||||
// enclosing class, and not a method.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C1 {
|
||||
|
||||
+6
-6
@@ -5,17 +5,17 @@
|
||||
// We emit an error if a const constructor has a body, even with the new,
|
||||
// shorter syntax.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C {
|
||||
final int x;
|
||||
const new(this.x) {}
|
||||
// [error column 3]
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
|
||||
|
||||
const new named(this.x) {}
|
||||
// [error column 3]
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [analyzer] SYNTACTIC_ERROR.CONST_CONSTRUCTOR_WITH_BODY
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// Using `new` to declare constructors.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C1 {
|
||||
@@ -17,7 +15,7 @@ class C1 {
|
||||
class C2 {
|
||||
int x;
|
||||
new() : x = 1 {} // Equivalent to `C1() : x = 1 {}`
|
||||
new named() : x = 1 {}// Equivalent to `C1.named() : x = 1 {}`
|
||||
new named() : x = 1 {} // Equivalent to `C1.named() : x = 1 {}`
|
||||
}
|
||||
|
||||
class C3 {
|
||||
|
||||
@@ -2,8 +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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class A() {
|
||||
this async {}
|
||||
// ^^^^^
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// Tests declaring constructors with various clauses.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
// Generics
|
||||
|
||||
+12
-14
@@ -5,33 +5,31 @@
|
||||
// It is an error to have the `const` keyword on both the header and body
|
||||
// part of a declaring constructor.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class const C1(final int x) {
|
||||
const this : assert(1 != 2);
|
||||
//^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 5]
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] Can't have modifier 'const' here.
|
||||
}
|
||||
|
||||
sealed class const C2(final int x) {
|
||||
const this : assert(1 != 2);
|
||||
//^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 5]
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] Can't have modifier 'const' here.
|
||||
}
|
||||
|
||||
extension type const C(int x) {
|
||||
const this : assert(1 != 2);
|
||||
//^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 5]
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] Can't have modifier 'const' here.
|
||||
}
|
||||
|
||||
enum const E1(final int x) {
|
||||
one(1);
|
||||
const this : assert(x != 2);
|
||||
//^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// [error column 3, length 5]
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] Can't have modifier 'const' here.
|
||||
}
|
||||
|
||||
@@ -5,37 +5,36 @@
|
||||
// A compile-time error occurs if a class, mixin class, enum, or extension type
|
||||
// has a constant primary constructor which has a body part that has a body.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class const A() {
|
||||
this {}
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
}
|
||||
|
||||
mixin class const M() {
|
||||
this {}
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// [cfe] Can't use 'M' as a mixin because it has constructors.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// [cfe] Can't use 'M' as a mixin because it has constructors.
|
||||
}
|
||||
|
||||
enum E(int x) {
|
||||
e(1);
|
||||
// [error column 3]
|
||||
// [cfe] A const constructor can't have a body.
|
||||
|
||||
this {}
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
}
|
||||
|
||||
extension type const Ext(int x) {
|
||||
this {}
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_PRIMARY_CONSTRUCTOR_WITH_BODY
|
||||
// [cfe] A const constructor can't have a body.
|
||||
}
|
||||
|
||||
@@ -6,37 +6,35 @@
|
||||
// form `this.v`, or `super.v` where `v` is an identifier, and the parameter has
|
||||
// the modifier `covariant`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// `covariant` with `this.x`
|
||||
|
||||
// In-header declaring constructor
|
||||
class C1(covariant this.x) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
int x;
|
||||
}
|
||||
|
||||
|
||||
class C2({covariant this.x}) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
int? x;
|
||||
}
|
||||
|
||||
class C3({required covariant this.x}) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
int x;
|
||||
}
|
||||
|
||||
class C4([covariant this.x]) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
int? x;
|
||||
}
|
||||
|
||||
@@ -46,21 +44,31 @@ class A(final int? x);
|
||||
|
||||
// In-header declaring constructor
|
||||
class C9(covariant super.x) extends A;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C10({covariant super.x}) extends A;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_SUPER_INITIALIZER_MISSING_ARGUMENTS
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.SUPER_FORMAL_PARAMETER_WITHOUT_ASSOCIATED_NAMED
|
||||
// [cfe] The super constructor has no corresponding named parameter.
|
||||
|
||||
class C11({required covariant super.x}) extends A;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_SUPER_INITIALIZER_MISSING_ARGUMENTS
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.SUPER_FORMAL_PARAMETER_WITHOUT_ASSOCIATED_NAMED
|
||||
// [cfe] The super constructor has no corresponding named parameter.
|
||||
|
||||
class C12([covariant super.x]) extends A;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
// Allow the modifier `covariant` in declaring parameters.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class A {}
|
||||
|
||||
class B extends A {}
|
||||
|
||||
class C1(covariant var A x);
|
||||
|
||||
@@ -4,34 +4,32 @@
|
||||
|
||||
// It is an error for a formal parameter to be both `covariant` and `final`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1(covariant final int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C2({covariant final int? x = 1});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C3({required covariant final int x});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C4([covariant final int? x]);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
extension type E1(covariant final int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
extension type E2(covariant int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
@@ -5,24 +5,22 @@
|
||||
// It is an error for a formal parameter to have the `covariant` modifier
|
||||
// but not the `var` modifier.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1(covariant int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C2({covariant int? x});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C3({required covariant int x});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
class C4([covariant int? x]);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.INVALID_COVARIANT_MODIFIER_IN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] The 'covariant' modifier can only be used on non-final declaring parameters.
|
||||
|
||||
@@ -2,30 +2,31 @@
|
||||
// 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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
// Enums that have an empty body (i.e. `;`) can be parsed, but will cause a
|
||||
// compile-time error when there's no enum constant declared.
|
||||
|
||||
enum E1;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ENUM_WITHOUT_CONSTANTS
|
||||
// [cfe] An enum declaration can't be empty.
|
||||
|
||||
enum E2(final int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ENUM_WITHOUT_CONSTANTS
|
||||
// [cfe] An enum declaration can't be empty.
|
||||
|
||||
enum const E3;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.CONST_WITHOUT_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] 'const' can only be used together with a primary constructor declaration.
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ENUM_WITHOUT_CONSTANTS
|
||||
// [cfe] An enum declaration can't be empty.
|
||||
|
||||
enum const E4(final int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.ENUM_WITHOUT_CONSTANTS
|
||||
// [cfe] An enum declaration can't be empty.
|
||||
|
||||
// Mixin application classes cannot have an explicit (empty) class body.
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// An empty declaration body, `{}`, can be replaced by `;`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class S1;
|
||||
class S2 extends S;
|
||||
class S3 with M;
|
||||
@@ -66,12 +64,17 @@ extension Ex2<T> on T;
|
||||
|
||||
// Helpers.
|
||||
interface class I {}
|
||||
|
||||
interface class J {}
|
||||
|
||||
interface class IJ implements I, J {}
|
||||
|
||||
class S {
|
||||
const S();
|
||||
}
|
||||
|
||||
mixin M {}
|
||||
|
||||
mixin N {}
|
||||
|
||||
class M1With with M1;
|
||||
|
||||
+3
-4
@@ -5,13 +5,12 @@
|
||||
// With the primary constructors feature, generative constructors in enums are
|
||||
// implicitly const and don't require the `const` keyword.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
enum E1 {
|
||||
e;
|
||||
new ();
|
||||
|
||||
new();
|
||||
}
|
||||
|
||||
enum E2(final int x) {
|
||||
@@ -26,7 +25,7 @@ enum E3 {
|
||||
e2.named(2);
|
||||
|
||||
final int x;
|
||||
new () : this.named(1);
|
||||
new() : this.named(1);
|
||||
new named(this.x);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// `external` instance variables cannot be introduced by a declaring parameter.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(external int x);
|
||||
// ^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// Declaring any formal parameters with the `final` modifier is a compile-time
|
||||
// error.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C {
|
||||
void method1(final int x) {}
|
||||
// ^^^^^
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// A basic declaring header constructor.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Point(var int x, var int y);
|
||||
@@ -34,14 +32,17 @@ class CSuperParameters(final int x, super.y) extends C1;
|
||||
class CNamedParameters({final int x = 1, required var int y});
|
||||
|
||||
enum EnumNamedParameters({final int x = 1, required final int y}) {
|
||||
e(x: 2, y: 3), f(y: 3);
|
||||
e(x: 2, y: 3),
|
||||
f(y: 3);
|
||||
}
|
||||
|
||||
// Optional parameters.
|
||||
class COptionalParameters([final int x = 1, var int y = 2]);
|
||||
|
||||
enum EnumOptionalParameters([final int x = 1, final int y = 2]) {
|
||||
e(3, 4), f(3), g();
|
||||
e(3, 4),
|
||||
f(3),
|
||||
g();
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
// A compile-time error occurs if a declaration has a primary constructor with
|
||||
// an initializing formal and no instance variable of the same name.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(this.x) {}
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD
|
||||
// ^
|
||||
// [cfe] 'x' isn't an instance field of this class.
|
||||
|
||||
|
||||
enum E(this.x) {
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD
|
||||
// ^
|
||||
// [cfe] 'x' isn't an instance field of this class.
|
||||
e(1);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
// `late` instance variables cannot be introduced by a declaring parameter.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C(late int x);
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
|
||||
@@ -6,27 +6,26 @@
|
||||
// constructor which is not trivial, that is, it declares one or more
|
||||
// parameters, or it has a body part that has an initializer list or a body.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
mixin class M1(int x);
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Can't use 'M1' as a mixin because it has constructors.
|
||||
|
||||
|
||||
mixin class M2(int x) {
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Can't use 'M2' as a mixin because it has constructors.
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Can't use 'M2' as a mixin because it has constructors.
|
||||
}
|
||||
|
||||
mixin class M3() {
|
||||
this : assert(true);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Can't use 'M3' as a mixin because it has constructors.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Can't use 'M3' as a mixin because it has constructors.
|
||||
}
|
||||
|
||||
mixin class M4() {
|
||||
@@ -35,7 +34,7 @@ mixin class M4() {
|
||||
|
||||
mixin class M5() {
|
||||
this {}
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// [cfe] Can't use 'M5' as a mixin because it has constructors.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MIXIN_CLASS_DECLARES_NON_TRIVIAL_GENERATIVE_CONSTRUCTOR
|
||||
// [cfe] Can't use 'M5' as a mixin because it has constructors.
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
|
||||
// Body and header constructor syntax for mixin classes.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
class C1 {}
|
||||
|
||||
mixin class M1() implements C1;
|
||||
|
||||
@@ -4,68 +4,66 @@
|
||||
|
||||
// Mixins cannot have declaring header/body constructors.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1;
|
||||
|
||||
mixin M1(var int x) implements C1;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M2(final int x) on C1;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M3(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M4.named(int x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M5();
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M6.named();
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
class C2<T>;
|
||||
|
||||
mixin M7<T>(var T x) implements C2<T>;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M8<T>(final T x) on C2<T>;
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M9<T>(T x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M10<T>.named(T x);
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M11<T>();
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
mixin M12<T>.named();
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MIXIN_PRIMARY_CONSTRUCTOR
|
||||
// [cfe] Mixins can't have primary constructors.
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// constructor, but the body contains a primary constructor body.
|
||||
// It is also an error to have multiple primary constructor bodies.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1 {
|
||||
this : assert(1 != 2);
|
||||
// [error column 3, length 4]
|
||||
@@ -39,6 +37,7 @@ class C3 {
|
||||
|
||||
enum E1 {
|
||||
e;
|
||||
|
||||
this : assert(1 != 2);
|
||||
// [error column 3, length 4]
|
||||
// [analyzer] COMPILE_TIME_ERROR.PRIMARY_CONSTRUCTOR_BODY_WITHOUT_DECLARATION
|
||||
@@ -47,6 +46,7 @@ enum E1 {
|
||||
|
||||
enum E2(int x) {
|
||||
e(1);
|
||||
|
||||
this;
|
||||
|
||||
this : assert(x != 2);
|
||||
|
||||
@@ -5,19 +5,17 @@
|
||||
// It is an error for a named parameter to be both `required` and have a
|
||||
// default value.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
class C1({required var int x = 0});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_ON_REQUIRED_PARAMETER
|
||||
// [cfe] Named parameter 'x' is required and can't have a default value.
|
||||
|
||||
class C2({required final int x = 0});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_ON_REQUIRED_PARAMETER
|
||||
// [cfe] Named parameter 'x' is required and can't have a default value.
|
||||
|
||||
class C3({required int x = 0});
|
||||
// ^
|
||||
// [analyzer] unspecified
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_ON_REQUIRED_PARAMETER
|
||||
// [cfe] Named parameter 'x' is required and can't have a default value.
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// It's a compile-time error to write a formal non-declaring parameter with a
|
||||
// `var` keyword and no type annotation.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
typedef void Logger(var message);
|
||||
// ^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
|
||||
+6
-9
@@ -5,8 +5,6 @@
|
||||
// Tests for type inference of declaring parameters in primary constructors,
|
||||
// including override inference and inference from default values.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:expect/static_type_helper.dart";
|
||||
|
||||
@@ -32,13 +30,11 @@ class DeclaringExtends(final x, var y) extends A {
|
||||
}
|
||||
|
||||
// Infer from default values.
|
||||
class DefaultValues(
|
||||
[
|
||||
final x = 1, // int
|
||||
var y = 'string', // String
|
||||
final z = null, // Object?
|
||||
]
|
||||
);
|
||||
class DefaultValues([
|
||||
final x = 1, // int
|
||||
var y = 'string', // String
|
||||
final z = null, // Object?
|
||||
]);
|
||||
|
||||
// `Object?` is the default when no default value is provided.
|
||||
class NoDefaultValue(final x, var y);
|
||||
@@ -54,6 +50,7 @@ class Implements(final x, var y) implements SimpleInterface;
|
||||
|
||||
// Inference from `implements` of a mixin with `on` clause.
|
||||
mixin MixinOn on SimpleInterface {}
|
||||
|
||||
class ImplementsMixinOn(final x, var y) implements MixinOn;
|
||||
|
||||
mixin SimpleMixin {
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// Tests that we infer `Object?` for an extension type's representation type if
|
||||
// the type isn't specified.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/static_type_helper.dart';
|
||||
|
||||
// Representation type is `Object?`, not `dynamic`.
|
||||
@@ -18,7 +16,7 @@ void main() {
|
||||
if (1 > 2) et3.i.arglebargle;
|
||||
// ^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
|
||||
// [cfe] unspecified
|
||||
// [cfe] The getter 'arglebargle' isn't defined for the type 'Object?'.
|
||||
|
||||
ET0(null).name.expectStaticType<Exactly<Object?>>();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// We can omit the type of an optional parameter with a default value, in which
|
||||
// case the type is inferred from the default value.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:expect/static_type_helper.dart";
|
||||
|
||||
@@ -20,7 +18,8 @@ class Named({final x = 1, var y = 2}) {
|
||||
}
|
||||
|
||||
enum NamedEnum({final x = 1}) {
|
||||
e(x: 2), f();
|
||||
e(x: 2),
|
||||
f();
|
||||
|
||||
final Object o;
|
||||
|
||||
@@ -41,7 +40,8 @@ class Optional([final x = 1, var y = 2]) {
|
||||
}
|
||||
|
||||
enum OptionalEnum([final x = 1]) {
|
||||
e(2), f();
|
||||
e(2),
|
||||
f();
|
||||
|
||||
final Object o;
|
||||
|
||||
|
||||
@@ -2,8 +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.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
// --------------------
|
||||
@@ -11,20 +9,19 @@ import 'package:expect/expect.dart';
|
||||
// constructor.
|
||||
|
||||
class CMultiple(var int _, var int _);
|
||||
// ^
|
||||
// [cfe] unspecified
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION
|
||||
// [cfe] '_' is already declared in this scope.
|
||||
|
||||
class DMultiple(final int _, final int _);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION
|
||||
// [cfe] unspecified
|
||||
// [cfe] '_' is already declared in this scope.
|
||||
|
||||
enum EnumMultiple(final int _, final int _) {
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION
|
||||
// [cfe] unspecified
|
||||
// [cfe] '_' is already declared in this scope.
|
||||
e1(1, 2);
|
||||
}
|
||||
|
||||
@@ -37,36 +34,36 @@ class C(var int _) {
|
||||
int x = _;
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
|
||||
this : assert(_ > 0);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
}
|
||||
|
||||
class D(final int _) {
|
||||
int x = _;
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
|
||||
this : assert(_ > 0);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
}
|
||||
|
||||
class E(int _, int _) {
|
||||
int x = _;
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Undefined name '_'.
|
||||
|
||||
this : assert(_ > 0);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Undefined name '_'.
|
||||
}
|
||||
|
||||
enum E1(final int _) {
|
||||
@@ -77,18 +74,18 @@ enum E1(final int _) {
|
||||
final int x = _;
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
|
||||
this : assert(_ > 0);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_CONSTANT
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
}
|
||||
|
||||
extension type Ext(int _) {
|
||||
this : assert(_ > 0);
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER
|
||||
// [cfe] unspecified
|
||||
// [cfe] Can't access 'this' in a field initializer to read '_'.
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
// instance members of C/D/E/Ext, if there is an instance variable with the
|
||||
// name `_`.
|
||||
|
||||
// SharedOptions=--enable-experiment=primary-constructors
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class C(var int _) {
|
||||
@@ -40,9 +38,11 @@ enum E1(final int _) {
|
||||
enum Enum1(final int _, int _) {
|
||||
e(1, 2);
|
||||
}
|
||||
|
||||
enum Enum2(int _, final int _) {
|
||||
e(1, 2);
|
||||
}
|
||||
|
||||
enum Enum3(int _, final int _, int _) {
|
||||
e(1, 2, 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user