#3330. Add tests for generative constructors. (#4264)
Add tests for generative constructors.
diff --git a/LanguageFeatures/Static-extensions/constructor_A01_t01.dart b/LanguageFeatures/Static-extensions/constructor_A01_t01.dart
new file mode 100644
index 0000000..8a18568
--- /dev/null
+++ b/LanguageFeatures/Static-extensions/constructor_A01_t01.dart
@@ -0,0 +1,59 @@
+// 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.
+
+/// @assertion It is a compile-time error to declare a constructor in an
+/// extension whose on-type is not regular-bounded, assuming that the type
+/// arguments substituted for the type parameters declared by the extension
+/// satisfy the bounds on the parameters.
+///
+/// @description Checks that it is a compile-time error to declare a
+/// non-redirecting factory constructor in an extension whose on-type is not
+/// regular-bounded. Test a class.
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=static-extensions
+
+class C<X extends C<X>> {}
+
+extension Ext1 on C<dynamic> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext2 on C<void> {
+ factory() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext3 on C<Object?> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+class A<T extends A<T, S>, S extends A<T, S>> {}
+
+extension Ext4 on A<dynamic, dynamic> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext5 on A<Object?, Object?> {
+ factory() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+main() {
+ print(C);
+ print(A);
+}
diff --git a/LanguageFeatures/Static-extensions/constructor_A01_t02.dart b/LanguageFeatures/Static-extensions/constructor_A01_t02.dart
new file mode 100644
index 0000000..d7c472a
--- /dev/null
+++ b/LanguageFeatures/Static-extensions/constructor_A01_t02.dart
@@ -0,0 +1,63 @@
+// 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.
+
+/// @assertion It is a compile-time error to declare a constructor in an
+/// extension whose on-type is not regular-bounded, assuming that the type
+/// arguments substituted for the type parameters declared by the extension
+/// satisfy the bounds on the parameters.
+///
+/// @description Checks that it is a compile-time error to declare a redirecting
+/// factory constructor in an extension whose on-type is not regular-bounded.
+/// Test a class.
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=static-extensions
+
+class C<X extends C<X>> {
+ C.named();
+}
+
+extension Ext1 on C<dynamic> {
+ factory foo() = C.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext2 on C<void> {
+ factory() = C.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext3 on C<Object?> {
+ factory foo() = C.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+class A<T extends A<T, S>, S extends A<T, S>> {
+ A.named();
+}
+
+extension Ext4 on A<dynamic, dynamic> {
+ factory foo() = A.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext5 on A<Object?, void> {
+ factory() = A.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+main() {
+ print(C);
+ print(A);
+}
diff --git a/LanguageFeatures/Static-extensions/constructor_A01_t03.dart b/LanguageFeatures/Static-extensions/constructor_A01_t03.dart
new file mode 100644
index 0000000..32b727f
--- /dev/null
+++ b/LanguageFeatures/Static-extensions/constructor_A01_t03.dart
@@ -0,0 +1,47 @@
+// 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.
+
+/// @assertion It is a compile-time error to declare a constructor in an
+/// extension whose on-type is not regular-bounded, assuming that the type
+/// arguments substituted for the type parameters declared by the extension
+/// satisfy the bounds on the parameters.
+///
+/// @description Checks that it is a compile-time error to declare a factory
+/// constructor in an extension whose on-type is not regular-bounded. Test a
+/// mixin.
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=static-extensions
+
+mixin M<X extends M<X>> {}
+
+class MO<X extends M<X>> extends Object with M<X> {
+ MO.named();
+}
+
+extension Ext1 on M<dynamic> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext2 on M<void> {
+ factory() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext3 on M<Object?> {
+ factory foo() = MO.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+main() {
+ print(M);
+ print(MO);
+}
diff --git a/LanguageFeatures/Static-extensions/constructor_A01_t04.dart b/LanguageFeatures/Static-extensions/constructor_A01_t04.dart
new file mode 100644
index 0000000..e305754
--- /dev/null
+++ b/LanguageFeatures/Static-extensions/constructor_A01_t04.dart
@@ -0,0 +1,44 @@
+// 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.
+
+/// @assertion It is a compile-time error to declare a constructor in an
+/// extension whose on-type is not regular-bounded, assuming that the type
+/// arguments substituted for the type parameters declared by the extension
+/// satisfy the bounds on the parameters.
+///
+/// @description Checks that it is a compile-time error to declare a factory
+/// constructor in an extension whose on-type is not regular-bounded. Test a
+/// mixin class.
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=static-extensions
+
+mixin class MC<X extends MC<X>> {
+ MC.named();
+}
+
+extension Ext1 on MC<dynamic> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext2 on MC<void> {
+ factory() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext3 on MC<Object?> {
+ factory foo() = MC.named;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+main() {
+ print(MC);
+}
diff --git a/LanguageFeatures/Static-extensions/constructor_A01_t05.dart b/LanguageFeatures/Static-extensions/constructor_A01_t05.dart
new file mode 100644
index 0000000..72b287e
--- /dev/null
+++ b/LanguageFeatures/Static-extensions/constructor_A01_t05.dart
@@ -0,0 +1,46 @@
+// 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.
+
+/// @assertion It is a compile-time error to declare a constructor in an
+/// extension whose on-type is not regular-bounded, assuming that the type
+/// arguments substituted for the type parameters declared by the extension
+/// satisfy the bounds on the parameters.
+///
+/// @description Checks that it is a compile-time error to declare a
+/// non-redirecting factory constructor in an extension whose on-type is not
+/// regular-bounded. Test an enum.
+/// @author sgrekhov22@gmail.com
+
+// SharedOptions=--enable-experiment=static-extensions
+
+enum E<X extends num> {
+ e0.bar();
+
+ E.bar();
+}
+
+extension Ext1 on E<dynamic> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext2 on E<void> {
+ factory() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+extension Ext3 on E<Object?> {
+ factory foo() => throw 0;
+//^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
+
+main() {
+ print(E);
+}