diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t25.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t25.dart new file mode 100644 index 0000000000..3c039c8203 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t25.dart @@ -0,0 +1,147 @@ +// 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 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's 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 the name of a positional +/// parameter of an augmenting function is `_` and the name of this parameter in +/// the original function is not `_`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +void topLevelFunction1(int x) {} +void topLevelFunction2([int _x = 2]) {} + +augment void topLevelFunction1(int _); +augment void topLevelFunction2([int _]); + +class C { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment class C { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +mixin M { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment mixin M { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +enum E { + e1; + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment enum E { + ; + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment extension Ext { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +extension type ET(int _) { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment extension type ET { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class MA = Object with M; + +main() { + topLevelFunction1(1); + topLevelFunction2(1); + + C.staticMethod1(1); + C.staticMethod2(); + C().instanceMethod1(1); + C().instanceMethod2(); + + M.staticMethod1(1); + M.staticMethod2(); + MA().instanceMethod1(1); + MA().instanceMethod2(); + + E.staticMethod1(1); + E.staticMethod2(); + E.e1.instanceMethod1(1); + E.e1.instanceMethod2(); + + Ext.staticMethod1(1); + Ext.staticMethod2(); + A().instanceMethod1(1); + A().instanceMethod2(); + + ET.staticMethod1(1); + ET.staticMethod2(); + ET(0).instanceMethod1(1); + ET(0).instanceMethod2(); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t26.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t26.dart new file mode 100644 index 0000000000..b9d39d62c6 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t26.dart @@ -0,0 +1,147 @@ +// 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 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's 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 the name of a positional +/// parameter of an augmenting function is `_` and the name of this parameter in +/// the original function is also `_`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +void topLevelFunction1(int _) {} +void topLevelFunction2([int _ = 2]) {} + +augment void topLevelFunction1(int _); +augment void topLevelFunction2([int _]); + +class C { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment class C { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +mixin M { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment mixin M { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +enum E { + e1; + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment enum E { + ; + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment extension Ext { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +extension type ET(int _) { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment extension type ET { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class MA = Object with M; + +main() { + topLevelFunction1(1); + topLevelFunction2(1); + + C.staticMethod1(1); + C.staticMethod2(); + C().instanceMethod1(1); + C().instanceMethod2(); + + M.staticMethod1(1); + M.staticMethod2(); + MA().instanceMethod1(1); + MA().instanceMethod2(); + + E.staticMethod1(1); + E.staticMethod2(); + E.e1.instanceMethod1(1); + E.e1.instanceMethod2(); + + Ext.staticMethod1(1); + Ext.staticMethod2(); + A().instanceMethod1(1); + A().instanceMethod2(); + + ET.staticMethod1(1); + ET.staticMethod2(); + ET(0).instanceMethod1(1); + ET(0).instanceMethod2(); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t27.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t27.dart new file mode 100644 index 0000000000..62d23a66b9 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t27.dart @@ -0,0 +1,191 @@ +// 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 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's 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 a compile-time error if the name of a +/// positional parameter in the original function is `_` and the name of this +/// parameter in an augmenting function is not `_`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +void topLevelFunction1(int _) {} +void topLevelFunction2([int _ = 2]) {} + +augment void topLevelFunction1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +augment void topLevelFunction2([int __]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment class C { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int __ = 2]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment mixin M { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int __ = 2]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e1; + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment enum E { + ; + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int __ = 2]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment extension Ext { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int __ = 2]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + static void staticMethod1(int _) {} + static void staticMethod2([int _ = 2]) {} + void instanceMethod1(int _) {} + void instanceMethod2([int _]) {} +} + +augment extension type ET { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int __ = 2]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelFunction1); + print(topLevelFunction2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t28.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t28.dart new file mode 100644 index 0000000000..8522f2fcbb --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t28.dart @@ -0,0 +1,127 @@ +// 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 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's 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 a compile-time error if the name of a +/// positional parameter is `_` and the name of this parameter in an augmenting +/// function is not `_`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +part 'augmenting_functions_A04_t28_lib.dart'; + +void topLevelFunction1(int x) {} +void topLevelFunction2([int _x = 2]) {} + +augment void topLevelFunction1(int _); +augment void topLevelFunction2([int _]); + +class C { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment class C { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +mixin M { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment mixin M { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +enum E { + e1; + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment enum E { + ; + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment extension Ext { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +extension type ET(int _) { + static void staticMethod1(int _x) {} + static void staticMethod2([int x = 2]) {} + void instanceMethod1(int x) {} + void instanceMethod2([int _x]) {} +} + +augment extension type ET { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +main() { + print(topLevelFunction1); + print(topLevelFunction2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t28_lib.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t28_lib.dart new file mode 100644 index 0000000000..3a7a32f2fb --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t28_lib.dart @@ -0,0 +1,142 @@ +// 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 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's 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 a compile-time error if the name of a +/// positional parameter is `_` and the name of this parameter in an augmenting +/// function is not `_`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +part of 'augmenting_functions_A04_t28.dart'; + +augment void topLevelFunction1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +augment void topLevelFunction2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + +augment class C { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment mixin M { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment enum E { + ; + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension Ext { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment extension type ET { + augment static void staticMethod1(int _x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static void staticMethod2([int x]); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod1(int x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + augment void instanceMethod2([int _x]); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t29.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t29.dart new file mode 100644 index 0000000000..31d70825b3 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t29.dart @@ -0,0 +1,235 @@ +// 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 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's a compile-time error if: +/// - The signature of the augmenting function does not match the signature of +/// the augmented function. +/// +/// @description Checks that if the name of a positional parameter was augmented +/// to `_` then it is a compile-time error to use an old name. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +void topLevelFunction1(int x); +void topLevelFunction2([int _x = 2]); + +augment void topLevelFunction1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment void topLevelFunction2([int _]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class C { + static void staticMethod1(int _x); + static void staticMethod2([int x = 2]); + void instanceMethod1(int x); + void instanceMethod2([int _x]); +} + +augment class C { + augment static void staticMethod1(int _) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment static void staticMethod2([int _]) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod2([int _ = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +mixin M { + static void staticMethod1(int _x); + static void staticMethod2([int x = 2]); + void instanceMethod1(int x); + void instanceMethod2([int _x]); +} + +augment mixin M { + augment static void staticMethod1(int _) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment static void staticMethod2([int _]) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod2([int _ = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +enum E { + e1; + static void staticMethod1(int _x); + static void staticMethod2([int x = 2]); + void instanceMethod1(int x); + void instanceMethod2([int _x]); +} + +augment enum E { + ; + augment static void staticMethod1(int _) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment static void staticMethod2([int _]) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod2([int _ = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _x); + static void staticMethod2([int x = 2]); + void instanceMethod1(int x); + void instanceMethod2([int _x]); +} + +augment extension Ext { + augment static void staticMethod1(int _) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment static void staticMethod2([int _]) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod2([int _ = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +extension type ET(int _) { + static void staticMethod1(int _x); + static void staticMethod2([int x = 2]); + void instanceMethod1(int x); + void instanceMethod2([int _x]); +} + +augment extension type ET { + augment static void staticMethod1(int _) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment static void staticMethod2([int _]) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod1(int _) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + augment void instanceMethod2([int _ = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +main() { + print(topLevelFunction1); + print(topLevelFunction2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A04_t30.dart b/LanguageFeatures/Augmentations/augmenting_functions_A04_t30.dart new file mode 100644 index 0000000000..a1b233d5e0 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_functions_A04_t30.dart @@ -0,0 +1,235 @@ +// 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 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's a compile-time error if: +/// - The signature of the augmenting function does not match the signature of +/// the augmented function. +/// +/// @description Checks that if the name of a positional parameter was augmented +/// to `_` then it is a compile-time error to use an old name. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +void topLevelFunction1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +void topLevelFunction2([int _x = 2]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +augment void topLevelFunction1(int _); +augment void topLevelFunction2([int _]); + +class C { + static void staticMethod1(int _x) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + static void staticMethod2([int x = 2]){ + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod2([int _x]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +augment class C { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +mixin M { + static void staticMethod1(int _x) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + static void staticMethod2([int x = 2]){ + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod2([int _x]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +augment mixin M { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +enum E { + e1; + static void staticMethod1(int _x) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + static void staticMethod2([int x = 2]){ + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod2([int _x]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +augment enum E { + ; + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +class A {} + +extension Ext on A { + static void staticMethod1(int _x) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + static void staticMethod2([int x = 2]){ + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod2([int _x]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +augment extension Ext { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +extension type ET(int _) { + static void staticMethod1(int _x) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } + static void staticMethod2([int x = 2]){ + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod1(int x) { + print(x); +// ^ +// [analyzer] unspecified +// [cfe] unspecified + } + void instanceMethod2([int _x]) { + print(_x); +// ^^ +// [analyzer] unspecified +// [cfe] unspecified + } +} + +augment extension type ET { + augment static void staticMethod1(int _); + augment static void staticMethod2([int _]); + augment void instanceMethod1(int _); + augment void instanceMethod2([int _ = 2]); +} + +main() { + print(topLevelFunction1); + print(topLevelFunction2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_functions_A08_t03.dart b/LanguageFeatures/Augmentations/augmenting_functions_A08_t03.dart index 8bcc21a2f0..aea90a1ca8 100644 --- a/LanguageFeatures/Augmentations/augmenting_functions_A08_t03.dart +++ b/LanguageFeatures/Augmentations/augmenting_functions_A08_t03.dart @@ -7,7 +7,7 @@ /// - A function is not complete after all augmentations are applied, unless /// it's an instance member and the surrounding class is abstract. /// -/// @description Checks that it is not an error if a function is make complete +/// @description Checks that it is not an error if a function is made complete /// by an augmentation by adding an `external` modifier. /// @author sgrekhov22@gmail.com