diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t01.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t01.dart new file mode 100644 index 0000000000..8f7624ef26 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t01.dart @@ -0,0 +1,149 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test augmentation by `Function`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable = () {}; + +augment abstract Function topLevelVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static final staticVariable = () {}; + var instanceVariable = () {}; +} + +augment class C { + augment static Function get staticVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function _); +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Function instanceVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = () {}; + var instanceVariable = () {}; +} + +augment mixin M { + augment static Function get staticVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function _); +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Function instanceVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = () {}; + final instanceVariable = () {}; +} + +augment enum E { + ; + augment static Function get staticVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function _); +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Function instanceVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable = () {}; +} + +augment extension Ext { + augment static Function get staticVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function _); +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(void Function() instanceVariable) { + static var staticVariable = () {}; +} + +augment extension type ET { + augment static Function get staticVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function _); +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Function instanceVariable; +// ^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t02.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t02.dart new file mode 100644 index 0000000000..480a5c14c8 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t02.dart @@ -0,0 +1,166 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different return types. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable1 = () => 42 as num; + +augment abstract int Function() topLevelVariable1; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +var topLevelVariable2 = () => 42 as num; + +augment abstract Object Function() topLevelVariable2; +// ^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = () => 42 as num; + var instanceVariable = () => 42 as num; +} + +augment class C { + augment static int Function() get staticVariable; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Object Function() instanceVariable; +// ^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = () => 42 as num; + var instanceVariable = () => 42 as num; +} + +augment mixin M { + augment static int Function() get staticVariable; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Object Function() instanceVariable; +// ^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = () => 42 as num; + final instanceVariable = () => 42 as num; +} + +augment enum E { + ; + augment static int Function() get staticVariable; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Object Function() instanceVariable; +// ^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = () => 42 as num; + static var staticVariable2 = () => 42 as num; +} + +augment extension Ext { + augment static int Function() get staticVariable1; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static int Function() get staticVariable2; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(num Function() instanceVariable) { + static var staticVariable = () => 42 as num; +} + +augment extension type ET { + augment static int Function() get staticVariable; +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(int Function() _); +// ^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Object Function() instanceVariable; +// ^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable1); + print(topLevelVariable2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t03.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t03.dart new file mode 100644 index 0000000000..54d4ae5269 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t03.dart @@ -0,0 +1,149 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different return types. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable = () {}; // The type is `Null Function()` + +augment abstract void Function() topLevelVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = () {}; + var instanceVariable = () {}; +} + +augment class C { + augment static void Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(void Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract void Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = () {}; + var instanceVariable = () {}; +} + +augment mixin M { + augment static void Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(void Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract void Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = () {}; + final instanceVariable = () {}; +} + +augment enum E { + ; + augment static void Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(void Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final void Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable = () {}; +} + +augment extension Ext { + augment static void Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(void Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(Null Function() instanceVariable) { + static var staticVariable = () {}; +} + +augment extension type ET { + augment static void Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(void Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final void Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t04.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t04.dart new file mode 100644 index 0000000000..bf9e8feb92 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t04.dart @@ -0,0 +1,166 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different number of formal parameters. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable1 = (num x) {}; // The type is `Null Function(num)` + +augment abstract Null Function(num x, {int y}) topLevelVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +var topLevelVariable2 = (num x) {}; + +augment abstract Null Function({num x}) topLevelVariable2; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = (num x) {}; + var instanceVariable = (num x) {}; +} + +augment class C { + augment static Null Function(num x, {int y}) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num x, {int y}) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function({int x}) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = (num x) {}; + var instanceVariable = (num x) {}; +} + +augment mixin M { + augment static Null Function(num x, {int y}) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num x, {int y}) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function({int x}) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = (num x) {}; + final instanceVariable = (num x) {}; +} + +augment enum E { + ; + augment static Null Function(num x, {int y}) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num x, {int y}) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function({int x}) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = (num x) {}; + static var staticVariable2 = (num x) {}; +} + +augment extension Ext { + augment static Null Function(num x, {int y}) get staticVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Null Function(num x, {int y}) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Null Function({int x}) get staticVariable2; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Null Function({int x}) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(Null Function(num x) instanceVariable) { + static var staticVariable = (num x) {}; +} + +augment extension type ET { + augment static Null Function(num x, {int y}) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num x, {int y}) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function({int x}) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable1); + print(topLevelVariable2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t05.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t05.dart new file mode 100644 index 0000000000..fd18654cf2 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t05.dart @@ -0,0 +1,166 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different number of formal parameters. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable1 = (num x) {}; // The type is `Null Function(num)` + +augment abstract Null Function(num, [int]) topLevelVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +var topLevelVariable2 = (num x) {}; + +augment abstract Null Function([num]) topLevelVariable2; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = (num x) {}; + var instanceVariable = (num x) {}; +} + +augment class C { + augment static Null Function(num, [int]) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num, [int]) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function([num]) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = (num x) {}; + var instanceVariable = (num x) {}; +} + +augment mixin M { + augment static Null Function(num, [int]) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num, [int]) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function([num]) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = (num x) {}; + final instanceVariable = (num x) {}; +} + +augment enum E { + ; + augment static Null Function(num, [int]) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num, [int]) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function([num]) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = (num x) {}; + static var staticVariable2 = (num x) {}; +} + +augment extension Ext { + augment static Null Function(num, [int]) get staticVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Null Function(num, [int]) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Null Function([num]) get staticVariable2; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Null Function([num]) _); +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(Null Function(num) instanceVariable) { + static var staticVariable = (num x) {}; +} + +augment extension type ET { + augment static Null Function(num, [int]) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(num, [int]) _); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function([num]) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable1); + print(topLevelVariable2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t06.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t06.dart new file mode 100644 index 0000000000..27b33353c7 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t06.dart @@ -0,0 +1,166 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different types of formal parameters. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable1 = (num _) {}; // The type is `Null Function(num)` + +augment abstract Null Function(int) topLevelVariable1; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +var topLevelVariable2 = (num _) {}; + +augment abstract Null Function(Object) topLevelVariable2; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = (num _) {}; + var instanceVariable = (num _) {}; +} + +augment class C { + augment static Null Function(int) get staticVariable; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(int) _); +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function(Object) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = (num _) {}; + var instanceVariable = (num _) {}; +} + +augment mixin M { + augment static Null Function(int) get staticVariable; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(int) _); +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function(Object) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = (num _) {}; + final instanceVariable = (num _) {}; +} + +augment enum E { + ; + augment static Null Function(int) get staticVariable; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(int) _); +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function(Object) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = (num _) {}; + static var staticVariable2 = (num _) {}; +} + +augment extension Ext { + augment static Null Function(int) get staticVariable1; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Null Function(int) _); +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Null Function(Object) get staticVariable2; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Null Function(Object) _); +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(Null Function(num) instanceVariable) { + static var staticVariable = (num _) {}; +} + +augment extension type ET { + augment static Null Function(int) get staticVariable; +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(int) _); +// ^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function(Object) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable1); + print(topLevelVariable2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t07.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t07.dart new file mode 100644 index 0000000000..7adf7f6cb6 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t07.dart @@ -0,0 +1,166 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different types of formal parameters. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable1 = (v) {}; // The type is `Null Function(dynamic)` + +augment abstract Null Function(Object?) topLevelVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +var topLevelVariable2 = (v) {}; + +augment abstract Null Function(void) topLevelVariable2; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = (v) {}; + var instanceVariable = (v) {}; +} + +augment class C { + augment static Null Function(Object?) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(Object?) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function(void) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = (v) {}; + var instanceVariable = (v) {}; +} + +augment mixin M { + augment static Null Function(Object?) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(Object?) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function(void) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = (v) {}; + final instanceVariable = (v) {}; +} + +augment enum E { + ; + augment static Null Function(Object?) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(Object?) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function(void) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = (v) {}; + static var staticVariable2 = (v) {}; +} + +augment extension Ext { + augment static Null Function(Object?) get staticVariable1; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Null Function(Object?) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Null Function(void) get staticVariable2; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Null Function(void) _); +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(void Function(dynamic) instanceVariable) { + static var staticVariable = (v) {}; +} + +augment extension type ET { + augment static Null Function(Object?) get staticVariable; +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function(Object?) _); +// ^^^^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function(void) instanceVariable; +// ^^^^^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable1); + print(topLevelVariable2); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t08.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t08.dart new file mode 100644 index 0000000000..73fefdf15c --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t08.dart @@ -0,0 +1,158 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different types of return type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +var topLevelVariable = () {}; // The type is `Null Function()` + +augment abstract Function() topLevelVariable; // dynamic Function() +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static var staticVariable = () {}; + var instanceVariable = () {}; +} + +augment class C { + augment static Function() get staticVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Function() instanceVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static var staticVariable = () {}; + var instanceVariable = () {}; +} + +augment mixin M { + augment static Function() get staticVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Function() instanceVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static var staticVariable = () {}; + final instanceVariable = () {}; +} + +augment enum E { + ; + augment static Function() get staticVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Function() instanceVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static var staticVariable1 = () {}; + static var staticVariable2 = () {}; +} + +augment extension Ext { + augment static Function() get staticVariable1; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Function() get staticVariable2; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(void Function() instanceVariable) { + static var staticVariable = () {}; +} + +augment extension type ET { + augment static Function() get staticVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Function() _); +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Function() instanceVariable; +// ^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t09.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t09.dart new file mode 100644 index 0000000000..2a98e2e80b --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t09.dart @@ -0,0 +1,158 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is a compile-time error if a function-typed +/// variable is augmented by another function-typed variable, but the function +/// types do not match. Test different types of return type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +Function() topLevelVariable = () {}; // The type is `dynamic Function()` + +augment abstract Null Function() topLevelVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + +class C { + static Function() staticVariable = () {}; + Function() instanceVariable = () {}; +} + +augment class C { + augment static Null Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + static Function() staticVariable = () {}; + Function() instanceVariable = () {}; +} + +augment mixin M { + augment static Null Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract Null Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + static Function() staticVariable = () {}; + final Function() instanceVariable = () {}; +} + +augment enum E { + ; + augment static Null Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + static Function() staticVariable1 = () {}; + static Function() staticVariable2 = () {}; +} + +augment extension Ext { + augment static Null Function() get staticVariable1; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable1(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static Null Function() get staticVariable2; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable2(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(Function() instanceVariable) { + static Function() staticVariable = () {}; +} + +augment extension type ET { + augment static Null Function() get staticVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment static set staticVariable(Null Function() _); +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + augment abstract final Null Function() instanceVariable; +// ^^^^^^^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t10.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t10.dart new file mode 100644 index 0000000000..34f26d91ad --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t10.dart @@ -0,0 +1,111 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is not an error if a function-typed variable is +/// augmented by another variable with the same type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +import '../../utils/static_type_helper.dart'; + +var topLevelVariable = (v) {}; + +augment abstract Null Function(dynamic v) topLevelVariable; + +class C { + static var staticVariable = (v) {}; + var instanceVariable = (v) {}; +} + +augment class C { + augment Null Function(dynamic v) get staticVariable; + augment void set staticVariable(Null Function(dynamic v) _); + augment abstract Null Function(dynamic v) instanceVariable; +} + +mixin M { + static var staticVariable = (v) {}; + var instanceVariable = (v) {}; +} + +augment mixin M { + augment Null Function(dynamic v) get staticVariable; + augment void set staticVariable(Null Function(dynamic v) _); + augment abstract Null Function(dynamic v) instanceVariable; +} + +enum E { + e0; + static var staticVariable = (v) {}; + final instanceVariable = (v) {}; +} + +augment enum E { + ; + augment Null Function(dynamic v) get staticVariable; + augment void set staticVariable(Null Function(dynamic v) _); + augment abstract final Null Function(dynamic v) instanceVariable; +} + +class A {} + +extension Ext on A { + static var staticVariable = (v) {}; +} + +augment extension Ext { + augment Null Function(dynamic v) get staticVariable; + augment void set staticVariable(Null Function(dynamic v) _); +} + +extension type ET(Null Function(dynamic v) instanceVariable) { + static var staticVariable = (v) {}; +} + +augment extension type ET { + augment Null Function(dynamic v) get staticVariable; + augment void set staticVariable(Null Function(dynamic v) _); + augment abstract final Null Function(dynamic v) instanceVariable; +} + +class MA = Object with M; + +main() { + topLevelVariable.expectStaticType>(); + C.staticVariable.expectStaticType>(); + C().instanceVariable.expectStaticType>(); + M.staticVariable.expectStaticType>(); + MA().instanceVariable.expectStaticType>(); + E.staticVariable.expectStaticType>(); + E.e0.instanceVariable.expectStaticType>(); + Ext.staticVariable.expectStaticType>(); + ET.staticVariable.expectStaticType>(); + ET((v){}).instanceVariable.expectStaticType>(); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t11.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t11.dart new file mode 100644 index 0000000000..0eac0ec4ca --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t11.dart @@ -0,0 +1,87 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is not an error if a function-typed variable is +/// augmented by another variable with no type specified. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +// TODO (sgrekhov) This test does not include static abstract variable +// declarations because the grammar doesn't derive them. See +// https://github.com/dart-lang/language/issues/4592 + +import '../../utils/static_type_helper.dart'; + +abstract Null Function(Null _) topLevelVariable; + +augment var topLevelVariable = (v) { + v.expectStaticType>(); +}; + +class C { + abstract Null Function(Null _) instanceVariable; +} + +augment class C { + augment var instanceVariable = (v) { + v.expectStaticType>(); + }; +} + +mixin M { + abstract Null Function(Null _) instanceVariable; +} + +augment mixin M { + augment var instanceVariable = (v) { + v.expectStaticType>(); + }; +} + +enum E { + e0; + abstract final Null Function(Null _) instanceVariable; +} + +augment enum E { + ; + augment final instanceVariable = (v) { + v.expectStaticType>(); + }; +} + +class MA = Object with M; + +main() { + topLevelVariable.expectStaticType>(); + C().instanceVariable.expectStaticType>(); + MA().instanceVariable.expectStaticType>(); + E.e0.instanceVariable.expectStaticType>(); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t12.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t12.dart new file mode 100644 index 0000000000..32687fba86 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t12.dart @@ -0,0 +1,82 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is not an error if a function-typed variable is +/// augmented by another variable with the same type. Test function type with +/// omitted return type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +// TODO (sgrekhov) This test does not include static abstract variable +// declarations because the grammar doesn't derive them. See +// https://github.com/dart-lang/language/issues/4592 + +import '../../utils/static_type_helper.dart'; + +dynamic foo() => 42; + +abstract Function() topLevelVariable; + +augment dynamic Function() topLevelVariable = foo; + +class C { + abstract Function() instanceVariable; +} + +augment class C { + augment dynamic Function() instanceVariable = foo; +} + +mixin M { + abstract Function() instanceVariable; +} + +augment mixin M { + augment dynamic Function() instanceVariable = foo; +} + +enum E { + e0; + abstract final Function() instanceVariable; +} + +augment enum E { + ; + augment final dynamic Function() instanceVariable = foo; +} + +class MA = Object with M; + +main() { + topLevelVariable.expectStaticType>(); + C().instanceVariable.expectStaticType>(); + MA().instanceVariable.expectStaticType>(); + E.e0.instanceVariable.expectStaticType>(); +} diff --git a/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t13.dart b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t13.dart new file mode 100644 index 0000000000..db7127da29 --- /dev/null +++ b/LanguageFeatures/Augmentations/augmenting_variables_getters_setters_A07_t13.dart @@ -0,0 +1,114 @@ +// Copyright (c) 2026, 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 getter or setter does not match the +/// signature of the augmented getter or setter. +/// +/// @description Check that it is not an error if a function-typed variable is +/// augmented by another variable with the same type. Test function type with +/// omitted return type. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=augmentations + +import '../../utils/static_type_helper.dart'; + +dynamic foo() => 42; + +dynamic Function() topLevelVariable = foo; + +augment abstract Function() topLevelVariable; + +class C { + static dynamic Function() staticVariable = foo; + dynamic Function() instanceVariable = foo; +} + +augment class C { + augment Function() get staticVariable; + augment set staticVariable(Function() _); + augment abstract Function() instanceVariable; +} + +mixin M { + static dynamic Function() staticVariable = foo; + dynamic Function() instanceVariable = foo; +} + +augment mixin M { + augment Function() get staticVariable; + augment set staticVariable(Function() _); + augment abstract Function() instanceVariable; +} + +enum E { + e0; + static dynamic Function() staticVariable = foo; + final dynamic Function() instanceVariable = foo; +} + +augment enum E { + ; + augment Function() get staticVariable; + augment set staticVariable(Function() _); + augment abstract final Function() instanceVariable; +} + +class A {} + +extension Ext on A { + static dynamic Function() staticVariable = foo; +} + +augment extension Ext { + augment Function() get staticVariable; + augment set staticVariable(Function() _); +} + +extension type ET(dynamic Function() instanceVariable) { + static dynamic Function() staticVariable = foo; +} + +augment extension Ext { + augment Function() get staticVariable; + augment set staticVariable(Function() _); + augment abstract final Function() instanceVariable; +} + +class MA = Object with M; + +main() { + topLevelVariable.expectStaticType>(); + C.staticVariable.expectStaticType>(); + C().instanceVariable.expectStaticType>(); + M.staticVariable.expectStaticType>(); + MA().instanceVariable.expectStaticType>(); + E.staticVariable.expectStaticType>(); + E.e0.instanceVariable.expectStaticType>(); + Ext.staticVariable.expectStaticType>(); + ET.staticVariable.expectStaticType>(); + ET((){}).instanceVariable.expectStaticType>(); +}