diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01.dart index 4c98f2cb70..b2a4a52b44 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01.dart @@ -4,32 +4,69 @@ /// @assertion It is a compile-time error if: /// ... -/// - The augmenting constructor parameters specify any default values. +/// - More than one declaration in the augmentation chain specifies a default +/// value for the same optional parameter. This is an error even in the case +/// where all of them are identical. /// -/// @description Checks that it is a compile-time error if the augmenting -/// constructor parameters specify any default values. +/// @description Checks that it is a compile-time error when both the augmenting +/// constructor parameters and the introductory declaration specify default +/// values. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros - -part 'augmenting_constructors_A02_t01_lib.dart'; +// SharedOptions=--enable-experiment=augmentations class C { C([int x = 0]); C.c1({int x = 0}); } +augment class C { + augment C([int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment C.c1({int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + enum E { - e0(0); + e0, e1.c1(); const E([int x = 0]); const E.c1({int x = 0}); } +augment enum E { + augment const E([int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment const E.c1({int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + extension type ET(int id) { ET.c1(this.id, [int x = 0]); ET.c2(this.id, {int x = 0}); } +augment extension type ET { + augment ET.c1(this.id, [int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment ET.c2(this.id, {int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + main() { print(C); print(E); diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01_lib.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01_lib.dart deleted file mode 100644 index c4810be966..0000000000 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t01_lib.dart +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2024, 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 augmenting constructor parameters specify any default values. -/// -/// @description Checks that it is a compile-time error if the augmenting -/// constructor parameters specify any default values. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A02_t01.dart'; - -augment class C { - augment C([int x = 0]); -// ^ -// [analyzer] unspecified -// [cfe] unspecified - - augment C.c1({int x = 0}); -// ^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment enum E { - augment e0; - augment const E([int x = 0]); -// ^ -// [analyzer] unspecified -// [cfe] unspecified - - augment const E.c1({int x = 0}); -// ^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment extension type ET { - augment ET.c1(this.id, [int x = 0]); -// ^ -// [analyzer] unspecified -// [cfe] unspecified - - augment ET.c2(this.id, {int x = 0}); -// ^ -// [analyzer] unspecified -// [cfe] unspecified -} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t03.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t03.dart new file mode 100644 index 0000000000..b1296e41fa --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t03.dart @@ -0,0 +1,88 @@ +// Copyright (c) 2024, 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: +/// ... +/// - More than one declaration in the augmentation chain specifies a default +/// value for the same optional parameter. This is an error even in the case +/// where all of them are identical. +/// +/// @description Checks that it is a compile-time error when more than one +/// augmenting constructor declaration specify default values. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +class C { + C([int x]); + C.c1({int x}); +} + +augment class C { + augment C([int x = 0]); + augment C.c1({int x = 0}); +} + +augment class C { + augment C([int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment C.c1({int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0, e1.c1(); + const E([int x]); + const E.c1({int x}); +} + +augment enum E { + augment const E([int x = 0]); + augment const E.c1({int x = 0}); +} + +augment enum E { + augment const E([int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment const E.c1({int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int id) { + ET.c1(this.id, [int x]); + ET.c2(this.id, {int x}); +} + +augment extension type ET { + augment ET.c1(this.id, [int x = 0]); + augment ET.c2(this.id, {int x = 0}); +} + +augment extension type ET { + augment ET.c1(this.id, [int x = 0]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + + augment ET.c2(this.id, {int x = 0}); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(E); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A02_t05.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t05.dart new file mode 100644 index 0000000000..efa0c10c62 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A02_t05.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2024, 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: +/// ... +/// - More than one declaration in the augmentation chain specifies a default +/// value for the same optional parameter. This is an error even in the case +/// where all of them are identical. +/// +/// @description Checks that it is not an error if an augmenting constructor +/// specifies default values for optional parameters. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +import '../../Utils/expect.dart'; + +class C { + int x; + C([int x]); + C.c1({int x}); +} + +augment class C { + augment C([int x = 1]) : x = x; + augment C.c1({int x = 2}) : x = x; +} + +enum E { + e0, e1.c1(); + + final int x; + const E([int x]); + const E.c1({int x}); +} + +augment enum E { + augment const E([int x = 1]) : x = x; + augment const E.c1({int x = 2}) : x = x; +} + +String log = ""; + +extension type ET(int id) { + ET.c1(this.id, [int x]); + ET.c2(this.id, {int x}); +} + +augment extension type ET { + augment ET.c1(this.id, [int x = 1]) : assert(() { + log = "$x"; + return true; + }()); + augment ET.c2(this.id, {int x = 2}) assert(() { + log = "$x"; + return true; + }()); +} + +main() { + Expect.equals(1, C().x); + Expect.equals(2, C.c1().x); + Expect.equals(1, E.e0.x); + Expect.equals(2, E.e1.x); + ET.c1(0); + if (assertStatementsEnabled()) { + Expect.equals("1", log); + } + ET.c2(0); + if (assertStatementsEnabled()) { + Expect.equals("2", log); + } +} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01.dart index 2b8136a693..5b7ae185c8 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01.dart @@ -11,18 +11,30 @@ /// constructor is `const` and the augmenting constructor is not. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros - -part 'augmenting_constructors_A03_t01_lib.dart'; +// SharedOptions=--enable-experiment=augmentations class C { const C(); } +augment class C { + augment C(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + extension type ET(int id) { const ET.foo(this.id); } +augment extension type ET { + augment ET.foo(this.id); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + main() { print(C); print(ET); diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01_lib.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01_lib.dart deleted file mode 100644 index bb915a7fa0..0000000000 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t01_lib.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2024, 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 introductory constructor is `const` and the augmenting constructor is -/// not or vice versa. -/// -/// @description Checks that it is a compile-time error if the introductory -/// constructor is `const` and the augmenting constructor is not. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A03_t01.dart'; - -augment class C { - augment C(); -// ^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment extension type ET { - augment ET.foo(this.id); -// ^^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02.dart index e5054dc951..1cc06e3d97 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02.dart @@ -11,18 +11,30 @@ /// constructor is `const` and the introductory constructor is not. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros - -part 'augmenting_constructors_A03_t02_lib.dart'; +// SharedOptions=--enable-experiment=augmentations class C { C(); } +augment class C { + augment const C(); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + extension type ET(int id) { ET.foo(this.id); } +augment extension type ET { + augment const ET.foo(this.id); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + main() { print(C); print(ET); diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02_lib.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02_lib.dart deleted file mode 100644 index 7a637382d6..0000000000 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A03_t02_lib.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2024, 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 introductory constructor is `const` and the augmenting constructor is -/// not or vice versa. -/// -/// @description Checks that it is a compile-time error if the introductory -/// constructor is `const` and the augmenting constructor is not. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A03_t02.dart'; - -augment class C { - augment const C(); -// ^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment extension type ET { - augment const ET.foo(this.id); -// ^^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01.dart index 78e98fb6c0..e8d983be3f 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01.dart @@ -11,20 +11,32 @@ /// constructor is marked `factory` and the augmenting constructor is not. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros - -part 'augmenting_constructors_A04_t01_lib.dart'; +// SharedOptions=--enable-experiment=augmentations class C { C(); factory C.foo() = C; } +augment class C { + augment C.foo(); +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + extension type ET(int id) { ET.foo(this.id); factory ET.bar(int id) = ET.foo; } +augment extension type ET { + augment ET.bar(int id); +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + main() { print(C); print(ET); diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01_lib.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01_lib.dart deleted file mode 100644 index 4301106a2c..0000000000 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t01_lib.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2024, 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 introductory constructor is marked `factory` and the augmenting -/// constructor is not, or vice versa. -/// -/// @description Checks that it is a compile-time error if the introductory -/// constructor is marked `factory` and the augmenting constructor is not. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A04_t01.dart'; - -augment class C { - augment C.foo(); -// ^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment extension type ET { - augment ET.bar(int id); -// ^^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02.dart index af150e1a89..1144a99e69 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02.dart @@ -11,20 +11,32 @@ /// constructor is marked `factory` and the introductory constructor is not. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros - -part 'augmenting_constructors_A04_t02_lib.dart'; +// SharedOptions=--enable-experiment=augmentations class C { C(); C.foo(); } +augment class C { + augment factory C.foo() = C; +// ^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + extension type ET(int id) { ET.foo(this.id); ET.bar(int id); } +augment extension type ET { + augment factory ET.bar(int id) = ET.foo; +// ^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + main() { print(C); print(ET); diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02_lib.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02_lib.dart deleted file mode 100644 index c687625bfd..0000000000 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A04_t02_lib.dart +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2024, 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 introductory constructor is marked `factory` and the augmenting -/// constructor is not, or vice versa. -/// -/// @description Checks that it is a compile-time error if the augmenting -/// constructor is marked `factory` and the introductory constructor is not. -/// @author sgrekhov22@gmail.com - -// SharedOptions=--enable-experiment=macros - -part of 'augmenting_constructors_A04_t02.dart'; - -augment class C { - augment factory C.foo() = C; -// ^^^^^ -// [analyzer] unspecified -// [cfe] unspecified -} - -augment extension type ET { - augment factory ET.bar(int id) = ET.foo; -}