diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t01.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t01.dart new file mode 100644 index 0000000000..644849addc --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t01.dart @@ -0,0 +1,61 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test a class. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,declaring-constructors + +import '../../Utils/expect.dart'; + +class C1 { + final int v; + const C1.foo(this.v); + const factory C1(int v) = C1.foo; +} + +class C2 { + int v; + C2.foo(this.v); + factory C2(int v) => C2.foo(v + 1); +} + +class C3 { + final int v; + const C3.foo(this.v); + const factory C3(int v); + + augment const factory C3(int v) = C3.foo; +} + +class C4 { + int v; + C4.foo(this.v); + factory C4(int v); + + augment factory C4(int v) => C4.foo(v + 1); +} + +main() { + var c1 = C1.new; + Expect.equals(1, c1(1).v); + var c2 = C2.new; + Expect.equals(2, c2(1).v); + var c3 = C3.new; + Expect.equals(1, c3(1).v); + var c4 = C4.new; + Expect.equals(2, c4(1).v); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t02.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t02.dart new file mode 100644 index 0000000000..552e3416d7 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t02.dart @@ -0,0 +1,37 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test a class and external constructors. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=declaring-constructors + +import '../../Utils/static_type_helper.dart'; + +class C1 { + external factory C1(); +} + +class C2 { + external const factory C2(); +} + +main() { + var c1 = C1.new; + c1.expectStaticType>(); + var c2 = C2.new; + c2.expectStaticType>(); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t03.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t03.dart new file mode 100644 index 0000000000..3b216bc693 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t03.dart @@ -0,0 +1,57 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test a mixin class. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,declaring-constructors + +import '../../Utils/static_type_helper.dart'; + +mixin class C1 { + const C1.foo(); + const factory C1() = C1.foo; +} + +mixin class C2 { + C2.foo(); + factory C2() => C2.foo(); +} + +mixin class C3 { + const C3.foo(); + const factory C3(); + + augment const factory C3() = C3.foo; +} + +mixin class C4 { + C4.foo(); + factory C4(); + + augment factory C4() => C4.foo(); +} + +main() { + var c1 = C1.new; + c1.expectStaticType>(); + var c2 = C2.new; + c2.expectStaticType>(); + var c3 = C3.new; + c3.expectStaticType>(); + var c4 = C4.new; + c4.expectStaticType>(); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t04.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t04.dart new file mode 100644 index 0000000000..3c3a7ce202 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t04.dart @@ -0,0 +1,37 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test a mixin class and external constructors. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=declaring-constructors + +import '../../Utils/static_type_helper.dart'; + +mixin class C1 { + external factory C1(); +} + +mixin class C2 { + external const factory C2(); +} + +main() { + var c1 = C1.new; + c1.expectStaticType>(); + var c2 = C2.new; + c2.expectStaticType>(); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t05.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t05.dart new file mode 100644 index 0000000000..34dd677dd4 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t05.dart @@ -0,0 +1,55 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test an extension type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,declaring-constructors + +import '../../Utils/expect.dart'; + +extension type const ET1.foo(int v) { + const factory ET1(int v) = ET1.foo; +} + +extension type ET2.foo(int v) { + factory ET2(int v) => ET2.foo(v + 1); +} + +extension type const ET3._(int v) { + const ET3.foo(this.v); + const factory ET3(int v); + + augment const factory ET3(int v) = ET3.foo; +} + +extension type ET4._(int v) { + ET4.foo(this.v); + factory ET4(int v); + + augment factory ET4(int v) => ET4.foo(v + 1); +} + +main() { + var et1 = ET1.new; + Expect.equals(1, et1(1).v); + var et2 = ET2.new; + Expect.equals(2, et2(1).v); + var et3 = ET3.new; + Expect.equals(1, et3(1).v); + var et4 = ET4.new; + Expect.equals(2, et4(1).v); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t06.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t06.dart new file mode 100644 index 0000000000..279fdb4dc0 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t06.dart @@ -0,0 +1,38 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test an extension type and external constructors. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=declaring-constructors + +import '../../Utils/expect.dart'; +import '../../Utils/static_type_helper.dart'; + +extension type ET1._(int v) { + external factory ET1(int v); +} + +extension type ET2._(int v) { + external const factory ET2(int v); +} + +main() { + var et1 = ET1.new; + et1.expectStaticType>(); + var et2 = ET2.new; + et2.expectStaticType>(); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t07.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t07.dart new file mode 100644 index 0000000000..a319384135 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t07.dart @@ -0,0 +1,46 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test an enum. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,declaring-constructors + +import '../../Utils/expect.dart'; + +enum E1 { + e0.foo(1); + + final int v; + const E1.foo(this.v); + factory E1() => E1.e0; +} + +enum E2 { + e0.foo(2); + + final int v; + const E2.foo(this.v); + factory E2(); + augment factory E2() => E2.e0; +} + +main() { + var e1 = E1.new; + Expect.equals(1, e1().v); + var e2 = E2.new; + Expect.equals(2, e2().v); +} diff --git a/LanguageFeatures/Primary-constructors/grammar_A05_t08.dart b/LanguageFeatures/Primary-constructors/grammar_A05_t08.dart new file mode 100644 index 0000000000..38af7a73e9 --- /dev/null +++ b/LanguageFeatures/Primary-constructors/grammar_A05_t08.dart @@ -0,0 +1,35 @@ +// 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. + +/// @assertion Consider a factory constructor declaration of the form +/// `factory C(...` optionally starting with zero or more of the modifiers +/// `const`, `augment`, or `external`. Assume that `C` is the name of the +/// enclosing class, mixin class, enum, or extension type. In this situation, +/// the declaration declares a constructor whose name is `C`. +/// +/// Without this special rule, such a declaration would declare a constructor +/// named `C.C`. With this rule it declares a constructor named `C`, which is +/// the same as today. +/// +/// @description Check that in case of a factory constructor declaration of the +/// form `factory C(...` the declaration declares a constructor whose name is +/// `C`. Test an enum and external constructors. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=declaring-constructors + +import '../../Utils/static_type_helper.dart'; + +enum E1 { + e0.foo(3); + + final int v; + const E1.foo(this.v); + external factory E1(); +} + +main() { + var e1 = E1.new; + e1.expectStaticType>(); +}