[tests] Declaring constructors - Remove in-body declaring constructor tests.
This CL removes any tests that involve in-body declaring constructors. We recently removed these declaring constructors from the primary
constructor feature,
Bug: https://github.com/dart-lang/sdk/issues/61687
Change-Id: I56c6617fa6caa16d78945b46b195f450838e5de4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459920
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/tests/language/declaring_constructors/body/extension_type_error_test.dart b/tests/language/declaring_constructors/body/extension_type_error_test.dart
deleted file mode 100644
index 660b4e0..0000000
--- a/tests/language/declaring_constructors/body/extension_type_error_test.dart
+++ /dev/null
@@ -1,51 +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.
-
-// It's a compile-time error if an extension type does not contain a declaring
-// constructor that has exactly one declaring parameter which is final. This is
-// the test for in-body constructors.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-extension type ET1 {
- this(var int i);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type ET2 {
- this(var i);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type ET3 {
- this(i);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type ET4 {
- this(final i, final x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type ET5 {
- this(int i, int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type ET6 {
- this(int i);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/body/extension_type_test.dart b/tests/language/declaring_constructors/body/extension_type_test.dart
deleted file mode 100644
index bc24a80..0000000
--- a/tests/language/declaring_constructors/body/extension_type_test.dart
+++ /dev/null
@@ -1,33 +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.
-
-// An in-body declaring constructor in an extension type can have additional
-// parameters, as long as exactly one parameter is declaring and is `final`.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-import 'package:expect/expect.dart';
-
-extension type ET1 {
- this(final int i);
-}
-
-extension type ET2 {
- this(int i, final int x);
-}
-
-extension type ET3 {
- this(int i, final x);
-}
-
-extension type ET4 {
- this(final i);
-}
-
-void main() {
- Expect.equals(1, ET1(1).i);
- Expect.equals(2, ET2(1, 2).x);
- Expect.equals(2, ET3(1, 2).x);
- Expect.equals(1, ET4(1).i);
-}
diff --git a/tests/language/declaring_constructors/body/in_body_initializer_test.dart b/tests/language/declaring_constructors/body/in_body_initializer_test.dart
deleted file mode 100644
index 8cb6092..0000000
--- a/tests/language/declaring_constructors/body/in_body_initializer_test.dart
+++ /dev/null
@@ -1,63 +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.
-
-// A declaring body constructor can have a body and an initializer list as well
-// as initializing formals, just like other constructors in the body.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-import 'package:expect/expect.dart';
-
-class C1 {
- int y;
- this(final int x) : y = x;
-}
-
-class C2 {
- this(final int x) : assert(x > 0);
-}
-
-class C3 extends C1 {
- // Will override the `x` instance variable in `C1`.
- this(final int x) : super(x + 1);
-}
-
-class C4 extends C1 {
- int y;
- this(int z) : y = z, assert(z > 0), super(z + 1);
-}
-
-extension type Ext1 {
- this(final int x) : assert(x > 0);
-}
-
-enum Enum1 {
- e(1);
-
- const this(final int x) : assert(x > 0);
-}
-
-enum const Enum2 {
- e(1);
-
- final int y;
- this(final int x) : y = x;
-}
-
-void main() {
- Expect.equals(1, C1(1).x);
- Expect.equals(1, C1(1).y);
-
- Expect.equals(1, C2(1).x);
-
- Expect.equals(1, C3(1).x);
-
- Expect.equals(2, C4(1).x);
- Expect.equals(1, C4(1).y);
-
- Expect.equals(1, Ext1(1).x);
-
- Expect.equals(1, Enum1.e.x);
- Expect.equals(1, Enum2.e.x);
-}
diff --git a/tests/language/declaring_constructors/body/optional_parameter_nonconstant_default_error_test.dart b/tests/language/declaring_constructors/body/optional_parameter_nonconstant_default_error_test.dart
deleted file mode 100644
index 596a1ff..0000000
--- a/tests/language/declaring_constructors/body/optional_parameter_nonconstant_default_error_test.dart
+++ /dev/null
@@ -1,26 +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.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-// Tests that declaring constructors with optional parameters cannot have
-// non-constant default values in a body declaring constructor.
-
-int f() => 0;
-
-class C {
- this([int x = f()]);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-enum E {
- e;
-
- const this([int x = f()]) {}
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/syntax/body_syntax_test.dart b/tests/language/declaring_constructors/syntax/body_syntax_test.dart
deleted file mode 100644
index 31feff0..0000000
--- a/tests/language/declaring_constructors/syntax/body_syntax_test.dart
+++ /dev/null
@@ -1,110 +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.
-
-// A basic declaring body constructor.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-import 'package:expect/expect.dart';
-
-class Point {
- this(var int x, var int y);
-}
-
-class PointFinal {
- this(final int x, final int y);
-}
-
-// Constant constructors.
-class CConst {
- const this(final int x);
-}
-
-extension type ExtConst {
- const this(final int x);
-}
-
-enum EnumConst {
- e(1);
-
- const this(final int x);
-}
-
-// Initializing parameters.
-class CInitParameters {
- late int y;
- this(this.y);
-}
-
-// Super parameters.
-class C1(final int y);
-class CSuperParameters extends C1{
- this(final int x, super.y);
-}
-
-// Named parameters (regular and required).
-class CNamedParameters {
- this({final int x = 1, required var int y});
-}
-
-enum EnumNamedParameters {
- e(x: 2, y: 3), f(y: 3);
-
- const this({final int x = 1, required var int y});
-}
-
-// Optional parameters.
-class COptionalParameters {
- this([final int x = 1, var int y = 2]);
-}
-
-enum EnumOptionalParameters {
- e(3, 4), f(3), g();
-
- const this([final int x = 1, var int y = 2]);
-}
-
-// TODO(kallentu): Add tests for the type being inferred from the default value.
-
-void main() {
- var p1 = Point(1, 2);
- Expect.equals(1, p1.x);
- Expect.equals(2, p1.y);
-
- p1.x = 3;
- Expect.equals(3, p1.x);
-
- var p2 = PointFinal(3, 4);
- Expect.equals(3, p2.x);
- Expect.equals(4, p2.y);
-
- Expect.equals(1, const CConst(1).x);
-
- Expect.equals(1, const ExtConst(1).x);
-
- Expect.equals(1, const EnumConst.e.x);
-
- Expect.equals(1, CInitParameters(1).y);
-
- Expect.equals(1, CSuperParameters(1, 2).x);
- Expect.equals(2, CSuperParameters(1, 2).y);
-
- Expect.equals(1, CNamedParameters(y: 2).x);
- Expect.equals(2, CNamedParameters(y: 2).y);
-
- Expect.equals(2, const EnumNamedParameters.e.x);
- Expect.equals(3, const EnumNamedParameters.e.y);
- Expect.equals(1, const EnumNamedParameters.f.x);
- Expect.equals(3, const EnumNamedParameters.f.y);
-
- Expect.equals(1, COptionalParameters().x);
- Expect.equals(2, COptionalParameters().y);
-
- Expect.equals(3, const EnumOptionalParameters.e.x);
- Expect.equals(4, const EnumOptionalParameters.e.y);
- Expect.equals(3, const EnumOptionalParameters.f.x);
- Expect.equals(2, const EnumOptionalParameters.f.y);
- Expect.equals(1, const EnumOptionalParameters.g.x);
- Expect.equals(2, const EnumOptionalParameters.g.y);
-}
diff --git a/tests/language/declaring_constructors/syntax/covariant_super_this_error_test.dart b/tests/language/declaring_constructors/syntax/covariant_super_this_error_test.dart
index 73ec92f..dbfd42b 100644
--- a/tests/language/declaring_constructors/syntax/covariant_super_this_error_test.dart
+++ b/tests/language/declaring_constructors/syntax/covariant_super_this_error_test.dart
@@ -40,39 +40,6 @@
int? x;
}
-// In-body declaring constructor
-class C5 {
- int? x;
- this(covariant this.x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C6 {
- int x;
- this({covariant this.x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C7 {
- int x;
- this({required covariant this.x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C8 {
- int? x;
- this([covariant this.x]);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
// `covariant` with `super.x`
class A(final int? x);
@@ -97,32 +64,3 @@
// ^
// [analyzer] unspecified
// [cfe] unspecified
-
-// In-body declaring constructor
-class C13 extends A {
- this(covariant super.x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C14 extends A {
- this({covariant super.x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C15 extends A {
- this({required covariant super.x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C16 extends A {
- this([covariant super.x]);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/syntax/covariant_var_test.dart b/tests/language/declaring_constructors/syntax/covariant_var_test.dart
index 7365064..c697d0d 100644
--- a/tests/language/declaring_constructors/syntax/covariant_var_test.dart
+++ b/tests/language/declaring_constructors/syntax/covariant_var_test.dart
@@ -23,34 +23,6 @@
class C4([covariant var A? x]);
class D4([var B? x]) implements C2;
-class C5 {
- this(covariant var A x);
-}
-class D5 implements C5 {
- this(var B x);
-}
-
-class C6 {
- this({covariant var A? x});
-}
-class D6 {
- this({var B? x});
-}
-
-class C7 {
- this({required covariant var A x});
-}
-class D7 {
- this({required var B x});
-}
-
-class C8 {
- this([covariant var A? x]);
-}
-class D8 {
- this([var B? x]);
-}
-
void main() {
A a = A();
B b = B();
@@ -67,17 +39,4 @@
Expect.equals(a, C4(a).x);
Expect.equals(b, D4(b).x);
-
- // In-body
- Expect.equals(a, C5(a).x);
- Expect.equals(b, D5(b).x);
-
- Expect.equals(a, C6(x: a).x);
- Expect.equals(b, D6(x: b).x);
-
- Expect.equals(a, C7(x: a).x);
- Expect.equals(b, D7(x: b).x);
-
- Expect.equals(a, C8(a).x);
- Expect.equals(b, D8(b).x);
}
diff --git a/tests/language/declaring_constructors/syntax/covariant_with_final_error_test.dart b/tests/language/declaring_constructors/syntax/covariant_with_final_error_test.dart
index 268162e..f3af511 100644
--- a/tests/language/declaring_constructors/syntax/covariant_with_final_error_test.dart
+++ b/tests/language/declaring_constructors/syntax/covariant_with_final_error_test.dart
@@ -26,34 +26,6 @@
// [analyzer] unspecified
// [cfe] unspecified
-class C5 {
- this(covariant final int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C6 {
- this({covariant final int? x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C7 {
- this({required covariant final int x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C8 {
- this([covariant final int? x]);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
extension type E1(covariant final int x);
// ^
// [analyzer] unspecified
diff --git a/tests/language/declaring_constructors/syntax/covariant_without_var_error_test.dart b/tests/language/declaring_constructors/syntax/covariant_without_var_error_test.dart
index b141b5c..15cb848 100644
--- a/tests/language/declaring_constructors/syntax/covariant_without_var_error_test.dart
+++ b/tests/language/declaring_constructors/syntax/covariant_without_var_error_test.dart
@@ -26,32 +26,3 @@
// ^
// [analyzer] unspecified
// [cfe] unspecified
-
-
-class C5 {
- this(covariant int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C6 {
- this({covariant int? x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C7 {
- this({required covariant int x});
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C8 {
- this([covariant int? x]);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/syntax/declaring_header_body_error_test.dart b/tests/language/declaring_constructors/syntax/declaring_header_body_error_test.dart
deleted file mode 100644
index aacc999..0000000
--- a/tests/language/declaring_constructors/syntax/declaring_header_body_error_test.dart
+++ /dev/null
@@ -1,22 +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.
-
-// It is an error to have a declaring parameter list both in the header and in
-// the body.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-class C1(var int x) {
- this(var int y);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-class C2(final int x) {
- this(final int y);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/syntax/late_external_error_test.dart b/tests/language/declaring_constructors/syntax/late_external_error_test.dart
index 3c05ea8..ebb709c 100644
--- a/tests/language/declaring_constructors/syntax/late_external_error_test.dart
+++ b/tests/language/declaring_constructors/syntax/late_external_error_test.dart
@@ -11,10 +11,3 @@
// ^
// [analyzer] unspecified
// [cfe] unspecified
-
-class C2 {
- this(late int x, external double d);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
diff --git a/tests/language/declaring_constructors/syntax/late_external_test.dart b/tests/language/declaring_constructors/syntax/late_external_test.dart
index beab6ab..48b795c 100644
--- a/tests/language/declaring_constructors/syntax/late_external_test.dart
+++ b/tests/language/declaring_constructors/syntax/late_external_test.dart
@@ -6,13 +6,13 @@
// SharedOptions=--enable-experiment=declaring-constructors
-class C2(this.x) {
+import "package:expect/expect.dart";
+
+class C1(this.x) {
late int x;
external double d;
}
-class C2 {
- late int x;
- external double d;
- this(this.x);
+void main() {
+ Expect.equals(1, C1(1).x);
}
diff --git a/tests/language/declaring_constructors/syntax/mixin_class_test.dart b/tests/language/declaring_constructors/syntax/mixin_class_test.dart
index 8868bd1..330f7f7 100644
--- a/tests/language/declaring_constructors/syntax/mixin_class_test.dart
+++ b/tests/language/declaring_constructors/syntax/mixin_class_test.dart
@@ -18,31 +18,15 @@
mixin class M4.named();
-mixin class M5 {
- this();
-}
-
-mixin class M6 {
- this.named();
-}
-
class C2<T> {}
-mixin class M7<T>() implements C2<T>;
+mixin class M5<T>() implements C2<T>;
-mixin class M8<T>() on C2<T>;
+mixin class M6<T>() on C2<T>;
-mixin class M9<T>();
+mixin class M7<T>();
-mixin class M10<T>.named();
-
-mixin class M11<T> {
- this();
-}
-
-mixin class M12<T> {
- this.named();
-}
+mixin class M8<T>.named();
// Used for testing the mixins.
@@ -50,26 +34,18 @@
class CImpl2 extends C1 with M2;
class CImpl3 with M3;
class CImpl4 with M4;
-class CImpl5 with M5;
-class CImpl6 with M6;
+class CImpl5<T> with M5<T>;
+class CImpl6<T> extends C2<T> with M6<T>;
class CImpl7<T> with M7<T>;
-class CImpl8<T> extends C2<T> with M8<T>;
-class CImpl9<T> with M9<T>;
-class CImpl10<T> with M10<T>;
-class CImpl11<T> with M11<T>;
-class CImpl12<T> with M12<T>;
+class CImpl8<T> with M8<T>;
void main() {
CImpl1();
CImpl2();
CImpl3();
CImpl4();
- CImpl5();
- CImpl6();
+ CImpl5<String>();
+ CImpl6<String>();
CImpl7<String>();
CImpl8<String>();
- CImpl9<String>();
- CImpl10<String>();
- CImpl11<String>();
- CImpl12<String>();
}
diff --git a/tests/language/declaring_constructors/syntax/mixin_error_test.dart b/tests/language/declaring_constructors/syntax/mixin_error_test.dart
index 5992691..bdd227a 100644
--- a/tests/language/declaring_constructors/syntax/mixin_error_test.dart
+++ b/tests/language/declaring_constructors/syntax/mixin_error_test.dart
@@ -38,118 +38,34 @@
// [analyzer] unspecified
// [cfe] unspecified
-mixin M7 {
- this(var int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M8 {
- this(final int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M9 {
- this(int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M10 {
- this.named(int x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M11 {
- this();
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M12 {
- this.named();
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
class C2<T>;
-mixin M13<T>(var T x) implements C2<T>;
+mixin M7<T>(var T x) implements C2<T>;
// ^
// [analyzer] unspecified
// [cfe] unspecified
-mixin M14<T>(final T x) on C2<T>;
+mixin M8<T>(final T x) on C2<T>;
// ^
// [analyzer] unspecified
// [cfe] unspecified
-mixin M15<T>(T x);
+mixin M9<T>(T x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
-mixin M16<T>.named(T x);
+mixin M10<T>.named(T x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
-mixin M17<T>();
+mixin M11<T>();
// ^
// [analyzer] unspecified
// [cfe] unspecified
-mixin M18<T>.named();
+mixin M12<T>.named();
// ^
// [analyzer] unspecified
// [cfe] unspecified
-
-mixin M19<T> {
- this(var T x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M20<T> {
- this(final T x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M21<T> {
- this(T x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M22<T> {
- this.named(T x);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M23<T> {
- this();
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
-
-mixin M24<T> {
- this.named();
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified)
-}
diff --git a/tests/language/declaring_constructors/syntax/multiple_declaring_constructors_error_test.dart b/tests/language/declaring_constructors/syntax/multiple_declaring_constructors_error_test.dart
deleted file mode 100644
index 1feaf78..0000000
--- a/tests/language/declaring_constructors/syntax/multiple_declaring_constructors_error_test.dart
+++ /dev/null
@@ -1,29 +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.
-
-// It's an error for a class to have two or more declaring constructors.
-
-// SharedOptions=--enable-experiment=declaring-constructors
-
-class C {
- this(var int x);
- this.named(var int y);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type E(final int x){
- this(final int y);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}
-
-extension type E(final int x){
- this.named(final int y);
- // ^
- // [analyzer] unspecified
- // [cfe] unspecified
-}