From 715052be6c2f9c0b4308206420041d8aff20450b Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 9 Dec 2025 11:12:53 +0200 Subject: [PATCH 1/3] #3182. Add tests for library prefix --- .../augmentation_libraries_lib.dart | 6 +- .../augmenting_constructors_A01_t19.dart | 81 +++++++++++ .../augmenting_constructors_A01_t19_part.dart | 59 ++++++++ .../augmenting_functions_A01_t13.dart | 136 ++++++++++++++++++ .../augmenting_functions_A01_t13_part.dart | 77 ++++++++++ 5 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart create mode 100644 LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart create mode 100644 LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart create mode 100644 LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart diff --git a/LanguageFeatures/Augmentations/augmentation_libraries_lib.dart b/LanguageFeatures/Augmentations/augmentation_libraries_lib.dart index 688b95805b..3d528ca20e 100644 --- a/LanguageFeatures/Augmentations/augmentation_libraries_lib.dart +++ b/LanguageFeatures/Augmentations/augmentation_libraries_lib.dart @@ -5,11 +5,13 @@ /// @description Common library for augmentation tests. /// @author sgrekhov22@gmail.com -// SharedOptions=--enable-experiment=macros +// SharedOptions=--enable-experiment=augmentations library augmentation_libraries_lib; -class AL {} +class AL { + const AL(); +} final class FinalClass {} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart new file mode 100644 index 0000000000..d8c747e90b --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart @@ -0,0 +1,81 @@ +// 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 We say that an augmenting function or constructor's signature +/// matches if: +/// - It has the same number of type parameters with the same type parameter +/// names (same identifiers) and bounds (after type annotation inheritance), +/// if any (same types, even if they may not be written exactly the same in +/// case one of the declarations needs to refer to a type using an import +/// prefix). +/// - The return type (if not omitted) is the same as the augmented +/// declaration's return type. +/// - It has the same number of positional and optional parameters as the +/// augmented declaration. +/// - It has the same set of named parameter names as the augmented declaration. +/// - For all corresponding pairs of parameters: +/// - They have the same type (if not omitted in the augmenting declaration). +/// - They have the same `required` and `covariant` modifiers. +/// - For all positional parameters: +/// - The augmenting function's parameter name is `_`, or +/// - The augmenting function's parameter name is the same as the name of the +/// corresponding positional parameter in every preceding declaration that +/// doesn't have `_` as its name. +/// ... +/// It is a compile-time error if: +/// - The signature of the augmenting function does not match the signature of +/// the augmented function. +/// +/// @description Checks that it is not an error if an augmentation uses a +/// parameter name with a library prefix. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,enhanced-parts + +import '../../Utils/expect.dart'; +import 'augmentation_libraries_lib.dart'; + +part 'augmenting_constructors_A01_t19_part.dart'; + +class C { + AL? a; + C(this.a); + C.foo([this.a]); + C.bar({this.a}); + C.baz({required this.a}); +} + +enum E { + e0(const AL()), + e1.foo(const AL()), + e2.bar(a: const AL()), + e3.baz(a: const AL()); + + final AL? a; + const E(this.a); + const E.foo([this.a]); + const E.bar({this.a}); + const E.baz({required this.a}); +} + +extension type ET._(AL? a) { + ET(this.a); + ET.foo([this.a]); + ET.bar({this.a}); + ET.baz({required this.a}); +} + +main() { + C(AL()); + C.foo(AL()); + C.bar(a: AL()); + C.baz(a: AL()); + + print(E); + + ET(AL()); + ET.foo(AL()); + ET.bar(a: AL()); + ET.baz(a: AL()); +} diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart new file mode 100644 index 0000000000..f74e5c055e --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart @@ -0,0 +1,59 @@ +// 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 We say that an augmenting function or constructor's signature +/// matches if: +/// - It has the same number of type parameters with the same type parameter +/// names (same identifiers) and bounds (after type annotation inheritance), +/// if any (same types, even if they may not be written exactly the same in +/// case one of the declarations needs to refer to a type using an import +/// prefix). +/// - The return type (if not omitted) is the same as the augmented +/// declaration's return type. +/// - It has the same number of positional and optional parameters as the +/// augmented declaration. +/// - It has the same set of named parameter names as the augmented declaration. +/// - For all corresponding pairs of parameters: +/// - They have the same type (if not omitted in the augmenting declaration). +/// - They have the same `required` and `covariant` modifiers. +/// - For all positional parameters: +/// - The augmenting function's parameter name is `_`, or +/// - The augmenting function's parameter name is the same as the name of the +/// corresponding positional parameter in every preceding declaration that +/// doesn't have `_` as its name. +/// ... +/// It is a compile-time error if: +/// - The signature of the augmenting function does not match the signature of +/// the augmented function. +/// +/// @description Checks that it is not an error if an augmentation uses a +/// parameter name with a library prefix. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,enhanced-parts + +part of 'augmenting_constructors_A01_t19.dart'; +import 'augmentation_libraries_lib.dart' as l; + +augment class C { + augment C(l.AL? a); + augment C.foo([l.AL? a]); + augment C.bar({l.AL? a}); + augment C.baz({required l.AL? a}); +} + +augment enum E { + ; + augment const E(l.AL? a); + augment const E.foo([l.AL? a]); + augment const E.bar({l.AL? a}); + augment const E.baz({required l.AL? a}); +} + +augment extension type ET { + augment ET(l.AL? a); + augment ET.foo([l.AL? a]); + augment ET.bar({l.AL? a}); + augment ET.baz({required l.AL? a}); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart new file mode 100644 index 0000000000..43fb9b2064 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart @@ -0,0 +1,136 @@ +// 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 A top-level function, static method, instance method, operator, +/// getter, or setter may be augmented to provide a body or add metadata. +/// +/// @description Checks that it is not an error if an augmentation uses a +/// parameter name with a library prefix. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,enhanced-parts + +import '../../Utils/expect.dart'; +import 'augmentation_libraries_lib.dart'; + +part 'augmenting_functions_A01_t13_part.dart'; + +void topLevelFunction1(AL a); +void topLevelFunction2([AL? a]); +void topLevelFunction3({AL? a}); +void topLevelFunction4({required AL a}); + +class C { + static void staticMethod1(AL a); + static void staticMethod2([AL? a]); + static void staticMethod3({AL? a}); + static void staticMethod4({required AL a}); + void instanceMethod1(AL a); + void instanceMethod2([AL? a]); + void instanceMethod3({AL? a}); + void instanceMethod4({required AL a}); +} + +mixin M { + static void staticMethod1(AL a); + static void staticMethod2([AL? a]); + static void staticMethod3({AL? a}); + static void staticMethod4({required AL a}); + void instanceMethod1(AL a); + void instanceMethod2([AL? a]); + void instanceMethod3({AL? a}); + void instanceMethod4({required AL a}); +} + +enum E { + e1; + + static void staticMethod1(AL a); + static void staticMethod2([AL? a]); + static void staticMethod3({AL? a}); + static void staticMethod4({required AL a}); + void instanceMethod1(AL a); + void instanceMethod2([AL? a]); + void instanceMethod3({AL? a}); + void instanceMethod4({required AL a}); +} + +class A {} + +extension Ext on A { + static void staticMethod1(AL a); + static void staticMethod2([AL? a]); + static void staticMethod3({AL? a}); + static void staticMethod4({required AL a}); + void instanceMethod1(AL a); + void instanceMethod2([AL? a]); + void instanceMethod3({AL? a}); + void instanceMethod4({required AL a}); +} + +extension type ET(int _) { + static void staticMethod1(AL a); + static void staticMethod2([AL? a]); + static void staticMethod3({AL? a}); + static void staticMethod4({required AL a}); + void instanceMethod1(AL a); + void instanceMethod2([AL? a]); + void instanceMethod3({AL? a}); + void instanceMethod4({required AL a}); +} + +class MA = Object with M; + +main() { + const a = AL(); + topLevelFunction1(a); + topLevelFunction2(a); + topLevelFunction3(a: a); + topLevelFunction4(a: a); + + C.staticMethod1(a); + C.staticMethod2(a); + C.staticMethod3(a: a); + C.staticMethod4(a: a); + C().instanceMethod1(a); + C().instanceMethod2(a); + C().instanceMethod3(a: a); + C().instanceMethod4(a: a); + + M.staticMethod1(a); + M.staticMethod2(a); + M.staticMethod3(a: a); + M.staticMethod4(a: a); + MA().instanceMethod1(a); + MA().instanceMethod2(a); + MA().instanceMethod3(a: a); + MA().instanceMethod4(a: a); + + E.staticMethod1(a); + E.staticMethod2(a); + E.staticMethod3(a: a); + E.staticMethod4(a: a); + E.e1.instanceMethod1(a); + E.e1.instanceMethod2(a); + E.e1.instanceMethod3(a: a); + E.e1.instanceMethod4(a: a); + + Ext.staticMethod1(a); + Ext.staticMethod2(a); + Ext.staticMethod3(a: a); + Ext.staticMethod4(a: a); + A().instanceMethod1(a); + A().instanceMethod2(a); + A().instanceMethod3(a: a); + A().instanceMethod4(a: a); + + ET.staticMethod1(a); + ET.staticMethod2(a); + ET.staticMethod3(a: a); + ET.staticMethod4(a: a); + ET(0).instanceMethod1(a); + ET(0).instanceMethod2(a); + ET(0).instanceMethod3(a: a); + ET(0).instanceMethod4(a: a); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart new file mode 100644 index 0000000000..b171e6457e --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart @@ -0,0 +1,77 @@ +// 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 A top-level function, static method, instance method, operator, +/// getter, or setter may be augmented to provide a body or add metadata. +/// +/// @description Checks that it is not an error if an augmentation uses a +/// parameter name with a library prefix. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations,enhanced-parts + +import 'augmentation_libraries_lib.dart' as l; + +part of 'augmenting_functions_A01_t13.dart'; + +augment void topLevelFunction1(l.AL a) {} +augment void topLevelFunction2([l.AL? a]) {} +augment void topLevelFunction3({l.AL? a}) {} +augment void topLevelFunction4({required l.AL a}) {} + +augment class C { + augment static void staticMethod1(l.AL a) {} + augment static void staticMethod2([l.AL? a]) {} + augment static void staticMethod3({l.AL? a}) {} + augment static void staticMethod4({required l.AL a}) {} + augment void instanceMethod1(l.AL a) {} + augment void instanceMethod2([l.AL? a]) {} + augment void instanceMethod3({l.AL? a}) {} + augment void instanceMethod4({required l.AL a}) {} +} + +augment mixin M { + augment static void staticMethod1(l.AL a) {} + augment static void staticMethod2([l.AL? a]) {} + augment static void staticMethod3({l.AL? a}) {} + augment static void staticMethod4({required l.AL a}) {} + augment void instanceMethod1(l.AL a) {} + augment void instanceMethod2([l.AL? a]) {} + augment void instanceMethod3({l.AL? a}) {} + augment void instanceMethod4({required l.AL a}) {} +} + +augment enum E { + ; + augment static void staticMethod1(l.AL a) {} + augment static void staticMethod2([l.AL? a]) {} + augment static void staticMethod3({l.AL? a}) {} + augment static void staticMethod4({required l.AL a}) {} + augment void instanceMethod1(l.AL a) {} + augment void instanceMethod2([l.AL? a]) {} + augment void instanceMethod3({l.AL? a}) {} + augment void instanceMethod4({required l.AL a}) {} +} + +augment extension Ext { + augment static void staticMethod1(l.AL a) {} + augment static void staticMethod2([l.AL? a]) {} + augment static void staticMethod3({l.AL? a}) {} + augment static void staticMethod4({required l.AL a}) {} + augment void instanceMethod1(l.AL a) {} + augment void instanceMethod2([l.AL? a]) {} + augment void instanceMethod3({l.AL? a}) {} + augment void instanceMethod4({required l.AL a}) {} +} + +augment extension type ET { + augment static void staticMethod1(l.AL a) {} + augment static void staticMethod2([l.AL? a]) {} + augment static void staticMethod3({l.AL? a}) {} + augment static void staticMethod4({required l.AL a}) {} + augment void instanceMethod1(l.AL a) {} + augment void instanceMethod2([l.AL? a]) {} + augment void instanceMethod3({l.AL? a}) {} + augment void instanceMethod4({required l.AL a}) {} +} From 990e0b9ab0adb018e6789276a919388816b8587f Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 10 Dec 2025 10:45:23 +0200 Subject: [PATCH 2/3] Fix wording --- .../Augmentations/augmenting_constructors_A01_t19.dart | 2 +- .../Augmentations/augmenting_constructors_A01_t19_part.dart | 2 +- .../Augmentations/augmenting_functions_A01_t13.dart | 2 +- .../Augmentations/augmenting_functions_A01_t13_part.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart index d8c747e90b..cd475dc79d 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart @@ -28,7 +28,7 @@ /// the augmented function. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with a library prefix. +/// parameter name with an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart index f74e5c055e..1e1182f21f 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart @@ -28,7 +28,7 @@ /// the augmented function. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with a library prefix. +/// parameter name with an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart index 43fb9b2064..8daa014944 100644 --- a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart @@ -6,7 +6,7 @@ /// getter, or setter may be augmented to provide a body or add metadata. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with a library prefix. +/// parameter name with an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart index b171e6457e..686a7f2862 100644 --- a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart @@ -6,7 +6,7 @@ /// getter, or setter may be augmented to provide a body or add metadata. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with a library prefix. +/// parameter name with an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts From 52370be55562af96ba552b805a66957dd3b1fad7 Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Wed, 10 Dec 2025 16:34:17 +0200 Subject: [PATCH 3/3] Implement review recommendations --- .../Augmentations/augmenting_constructors_A01_t19.dart | 2 +- .../Augmentations/augmenting_constructors_A01_t19_part.dart | 2 +- .../Augmentations/augmenting_functions_A01_t13.dart | 2 +- .../Augmentations/augmenting_functions_A01_t13_part.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart index cd475dc79d..99d632d836 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19.dart @@ -28,7 +28,7 @@ /// the augmented function. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with an import prefix. +/// parameter whose type annotation uses an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart index 1e1182f21f..651bbd5a2e 100644 --- a/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart +++ b/LanguageFeatures/Augmentations/augmenting_constructors_A01_t19_part.dart @@ -28,7 +28,7 @@ /// the augmented function. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with an import prefix. +/// parameter whose type annotation uses an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart index 8daa014944..970c9357e6 100644 --- a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13.dart @@ -6,7 +6,7 @@ /// getter, or setter may be augmented to provide a body or add metadata. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with an import prefix. +/// parameter whose type annotation uses an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart index 686a7f2862..911de87bd4 100644 --- a/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart +++ b/LanguageFeatures/Augmentations/augmenting_functions_A01_t13_part.dart @@ -6,7 +6,7 @@ /// getter, or setter may be augmented to provide a body or add metadata. /// /// @description Checks that it is not an error if an augmentation uses a -/// parameter name with an import prefix. +/// parameter whose type annotation uses an import prefix. /// @author sgrekhov22@gmail.com // SharedOptions=--enable-experiment=augmentations,enhanced-parts