diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t14.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t14.dart new file mode 100644 index 0000000000..8e7a860490 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t14.dart @@ -0,0 +1,24 @@ +// 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 A compile-time error occurs if a declaration with the basename +/// `augmented` occurs in a location where any enclosing declaration is +/// augmenting. +/// +/// @description Checks that it is a compile-time error to augment a class named +/// `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class augmented {} + +augment class augmented {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(augmented); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t15.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t15.dart new file mode 100644 index 0000000000..042b8365ac --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t15.dart @@ -0,0 +1,24 @@ +// 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 A compile-time error occurs if a declaration with the basename +/// `augmented` occurs in a location where any enclosing declaration is +/// augmenting. +/// +/// @description Checks that it is a compile-time error to augment a mixin named +/// `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +mixin augmented {} + +augment mixin augmented {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(augmented); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t16.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t16.dart new file mode 100644 index 0000000000..fc6b2ddc11 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t16.dart @@ -0,0 +1,28 @@ +// 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 A compile-time error occurs if a declaration with the basename +/// `augmented` occurs in a location where any enclosing declaration is +/// augmenting. +/// +/// @description Checks that it is a compile-time error to augment an enum named +/// `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +enum augmented { + e0; +} + +augment enum augmented { +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + e1; +} + +main() { + print(augmented); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t17.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t17.dart new file mode 100644 index 0000000000..5077c8642c --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t17.dart @@ -0,0 +1,26 @@ +// 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 A compile-time error occurs if a declaration with the basename +/// `augmented` occurs in a location where any enclosing declaration is +/// augmenting. +/// +/// @description Checks that it is a compile-time error to augment an extension +/// named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class A {} + +extension augmented on A {} + +augment extension augmented {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(A); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t18.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t18.dart new file mode 100644 index 0000000000..8bcd589aa7 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A09_t18.dart @@ -0,0 +1,24 @@ +// 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 A compile-time error occurs if a declaration with the basename +/// `augmented` occurs in a location where any enclosing declaration is +/// augmenting. +/// +/// @description Checks that it is a compile-time error to augment an extension +/// type named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +extension type augmented(int _) {} + +augment extension type augmented {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +main() { + print(augmented); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t28.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t28.dart new file mode 100644 index 0000000000..41d92cf510 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t28.dart @@ -0,0 +1,61 @@ +// 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 The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting non-redirecting generative constructors: Unlike other +/// functions, `augmented` has no special meaning in non-redirecting +/// generative constructors. It is still a reserved word inside the body of +/// these constructors, since they are within the scope of an augmenting +/// declaration. +/// +/// @description Checks that it is a compile-time error for an augmenting +/// non-redirecting generative constructor to initialize a member named +/// `augmented` in the initializer list. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class C { + int augmented; + C(this.augmented); +} + +augment class C { + C.foo() : augmented = 1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + a0(0); + final int augmented; + const E(this.augmented); +} + +augment enum E { + a1.foo(); + const E.foo() : augmented = 1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int augmented) {} + +augment extension type ET { + ET.foo() : augmented = 1 {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(E); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t29.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t29.dart new file mode 100644 index 0000000000..5528bd56a7 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t29.dart @@ -0,0 +1,63 @@ +// 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 The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting non-redirecting generative constructors: Unlike other +/// functions, `augmented` has no special meaning in non-redirecting +/// generative constructors. It is still a reserved word inside the body of +/// these constructors, since they are within the scope of an augmenting +/// declaration. +/// +/// @description Checks that it is a compile-time error for an augmenting +/// non-redirecting generative constructor to use a variable named `augmented` +/// in the initializer list. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +const augmented = 1; + +class C { + int id; + C(this.id); +} + +augment class C { + C.foo() : id = augmented; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + a0(0); + final int id; + const E(this.id); +} + +augment enum E { + a1.foo(); + const E.foo() : id = augmented; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int id) {} + +augment extension type ET { + ET.foo() : id = augmented; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(E); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/extension_types_A02_t06.dart b/LanguageFeatures/Augmentation-libraries/extension_types_A02_t06.dart index bbd56bafbd..3335894855 100644 --- a/LanguageFeatures/Augmentation-libraries/extension_types_A02_t06.dart +++ b/LanguageFeatures/Augmentation-libraries/extension_types_A02_t06.dart @@ -19,4 +19,9 @@ extension type ET(int id) {} main() { Expect.equals(1, ET(1).id); + if (assertStatementsEnabled) { + Expect.throws(() { + ET(-1); + }); + } }