diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A05_t02.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A05_t02.dart new file mode 100644 index 0000000000..20eabc32c3 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A05_t02.dart @@ -0,0 +1,56 @@ +// 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 It is a compile-time error if: +/// ... +/// - The augmentation chain has exactly one specification of a default value +/// for an optional parameter, and the constructor is a redirecting factory. +/// +/// @description Checks that it is a compile-time error if the augmentation +/// chain has exactly one specification of a default value for an optional +/// parameter, but the constructor is a redirecting factory. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +class C { + C([int x = 0]); + C._({int x = 0}); + factory C.foo([int x]) = C; + factory C.bar({int x}) = C._; +} + +augment class C { + augment factory C.foo([int x = 0]); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment factory C.bar({int x = 0}); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int x) { + ET.c1([this.x = 0]); + ET.c2({this.x = 0}); + factory ET.foo([int x]) = ET.c1; + factory ET.bar({int x}) = ET.c2; +} + +augment extension type ET { + augment ET.foo([int x = 0]); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment ET.bar({int x = 0}); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A06_t01.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A06_t01.dart new file mode 100644 index 0000000000..7cbac04e9e --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A06_t01.dart @@ -0,0 +1,124 @@ +// 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 It is a compile-time error if: +/// ... +/// - No declaration in the augmentation chain specifies a default value for an +/// optional parameter whose declared type is potentially non-nullable, and +/// the constructor is not a redirecting factory. +/// +/// @description Checks that it is a compile-time error if no declaration in the +/// augmentation chain specifies a default value for an optional parameter whose +/// declared type is potentially non-nullable, and the constructor is not a +/// redirecting factory. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +class C { + C(int x); + C.c1([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + C.c2({int x}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + C.c3([int x]) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + C.c4({int x}) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + factory C.c5([int x]) => C(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + factory C.c6({int x}) => C(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment class C { + augment C.c1([int x]) {} + augment C.c2({int x}) {} + augment C.c3([int x]); + augment C.c4({int x}); + augment factory C.c5([int x]); + augment factory C.c6({int x}); +} + +enum E { + e0(0); + + const E(int x); + const E.c1([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const E.c2({int x}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const E.c3([int x]) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + const E.c4({int x}) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment enum E { + augment const E.c1([int x]) {} + augment const E.c2({int x}) {} + augment const E.c3([int x]); + augment const E.c4({int x}); +} + +extension type ET(int x) { + ET.c1([this.x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + ET.c2({this.x}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + ET.c3([int x]) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + ET.c4({int x}) : this(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + factory ET.c5([int x]) => ET(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + factory ET.c6({int x}) => ET(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment ET.c1([this.x]) {} + augment ET.c2({this.x}) {} + augment ET.c3([int x]); + augment ET.c4({int x}); + augment factory ET.c5([int x]); + augment factory ET.c6({int x}); +} + +main() { + print(C); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A07_t01.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A07_t01.dart new file mode 100644 index 0000000000..636b0473b9 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A07_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 It is a compile-time error if: +/// ... +/// - A factory constructor is incomplete after all augmentations are applied. +/// +/// @description Checks that it is a compile-time error if a factory constructor +/// is incomplete after all augmentations are applied. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +class C { + C(int x); + factory C.f1(); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + factory C.f2([int x]); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + factory C.f3({int x}); +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment class C { + augment factory C.f1(); + augment factory C.f2([int x = 0]); + augment factory C.f3({int x = 0}); +} + +extension type ET(int x) { + factory ET.f1(); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + factory ET.f2([int x]); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + factory ET.f3({int x}); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment factory ET.f1(); + augment factory ET.f2([int x = 0]); + augment factory ET.f3({int x = 0}); +} + +main() { + print(C); + print(ET); +}