diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A01_t28.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A01_t28.dart new file mode 100644 index 0000000000..15302f07a9 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A01_t28.dart @@ -0,0 +1,197 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// - Augmenting getters: Within an augmenting getter `augmented` invokes the +/// augmented getter and evaluates to its return value. If augmenting a +/// variable with a getter, this will invoke the implicitly induced getter +/// from the augmented variable declaration. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting getter has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class augmented { + const augmented(); +} + +@augmented() +String get topLevelGetter => "Original"; + +@augmented() +augment String get topLevelGetter; + +class C { + @augmented() + static String get staticGetter1 => "Original"; + @augmented() + String get instanceGetter1 => "Original"; + + @augmented() + augment static String get staticGetter1; + @augmented() + augment String get instanceGetter1; +} + +augment class C { + @augmented() augment static String get staticGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static String get staticGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment String get instanceGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String get instanceGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + @augmented() + static String get staticGetter1 => "Original"; + @augmented() + String get instanceGetter1 => "Original"; + + @augmented() + augment static String get staticGetter1; + @augmented() + augment String get instanceGetter1; +} + +augment mixin M { + @augmented() augment static String get staticGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static String get staticGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment String get instanceGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String get instanceGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + + @augmented() + static String get staticGetter1 => "Original"; + @augmented() + String get instanceGetter1 => "Original"; + + @augmented() + augment static String get staticGetter1; + @augmented() + augment String get instanceGetter1; +} + +augment enum E { + e1; + + @augmented() augment static String get staticGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static String get staticGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment String get instanceGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String get instanceGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + @augmented() + static String get staticGetter1 => "Original"; + @augmented() + String get instanceGetter1 => "Original"; + + @augmented() + augment static String get staticGetter1; + @augmented() + augment String get instanceGetter1; +} + +augment extension Ext { + @augmented() augment static String get staticGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static String get staticGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment String get instanceGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String get instanceGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + @augmented() + static String get staticGetter1 => "Original"; + @augmented() + String get instanceGetter1 => "Original"; + + @augmented() + augment static String get staticGetter1; + @augmented() + augment String get instanceGetter1; +} + +augment extension type ET { + @augmented() augment static String get staticGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static String get staticGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment String get instanceGetter1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String get instanceGetter2 => "Augmented"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + topLevelGetter; + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t26.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t26.dart new file mode 100644 index 0000000000..e89d56a355 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A02_t26.dart @@ -0,0 +1,196 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting setters: Within an augmenting setter `augmented` must be +/// followed by an `=` and will directly invoke the augmented setter. If +/// augmenting a variable with a setter, this will invoke the implicitly +/// induced setter from the augmented variable declaration. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting setter has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +const augmented = 0; + +@augmented +void set topLevelSetter(String value) {} + +@augmented +augment void set topLevelSetter(String value) {} + +class C { + @augmented + static void set staticSetter1(String value) {} + @augmented + void set instanceSetter1(String value) {} + + @augmented + augment static void set staticSetter1(String value); + @augmented + augment void set instanceSetter1(String value); +} + +augment class C { + @augmented augment static void set staticSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented static void set staticSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment void set instanceSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented void set instanceSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + @augmented + static void set staticSetter1(String value) {} + @augmented + void set instanceSetter1(String value) {} + + @augmented + augment static void set staticSetter1(String value); + @augmented + augment void set instanceSetter1(String value); +} + +augment mixin M { + @augmented augment static void set staticSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented static void set staticSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment void set instanceSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented void set instanceSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + + @augmented + static void set staticSetter1(String value) {} + @augmented + void set instanceSetter1(String value) {} + + @augmented + augment static void set staticSetter1(String value); + @augmented + augment void set instanceSetter1(String value); +} + +augment enum E { + e1; + + @augmented augment static void set staticSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented static void set staticSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment void set instanceSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented void set instanceSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + @augmented + static void set staticSetter1(String value) {} + @augmented + void set instanceSetter1(String value) {} + + @augmented + augment static void set staticSetter1(String value); + @augmented + augment void set instanceSetter1(String value); +} + +augment extension Ext { + @augmented augment static void set staticSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented static void set staticSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment void set instanceSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented void set instanceSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + @augmented + static void set staticSetter1(String value) {} + @augmented + void set instanceSetter1(String value) {} + + @augmented + augment static void set staticSetter1(String value); + @augmented + augment void set instanceSetter1(String value); +} + +augment extension type ET { + @augmented augment static void set staticSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented static void set staticSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment void set instanceSetter1(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented void set instanceSetter2(String value) {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + topLevelSetter = "1"; + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t33.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t33.dart new file mode 100644 index 0000000000..dcf3a92f73 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A03_t33.dart @@ -0,0 +1,268 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting fields: Within an augmenting variable declaration, `augmented` +/// can only be used in an initializer expression, and refers to the augmented +/// variable's initializing expression, which is immediately evaluated. +/// +/// It is a compile-time error to use `augmented` in an augmenting variable's +/// initializer if the member being augmented is not a variable declaration with +/// an initializing expression. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting field has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class augmented { + const augmented(); +} + +@augmented() +var topLevelVariable = "Original"; +@augmented() +final finalTopLevelVariable = "Original"; + +@augmented() +augment var topLevelVariable = "Augment"; + +@augmented() +augment final finalTopLevelVariable = "Augment"; + + +class C { + @augmented() + static var staticVariable1 = "Original"; + @augmented() + static final finalStaticVariable1 = "Original"; + @augmented() + var instanceVariable1 = "Original"; + @augmented() + final finalInstanceVariable1 = "Original"; + + @augmented() + augment static var staticVariable1; + @augmented() + augment static final finalStaticVariable1; + @augmented() + augment var instanceVariable1; + @augmented() + augment final finalInstanceVariable1; +} + +augment class C { + @augmented() augment static var staticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment static final finalStaticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment var instanceVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment final finalInstanceVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static var staticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static final finalStaticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() var instanceVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() final finalInstanceVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + @augmented() + static var staticVariable1 = "Original"; + @augmented() + static final finalStaticVariable1 = "Original"; + @augmented() + var instanceVariable1 = "Original"; + @augmented() + final finalInstanceVariable1 = "Original"; + + @augmented() + augment static var staticVariable1; + @augmented() + augment static final finalStaticVariable1; + @augmented() + augment var instanceVariable1; + @augmented() + augment final finalInstanceVariable1; +} + +augment mixin M { + @augmented() augment static var staticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment static final finalStaticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment var instanceVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment final finalInstanceVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static var staticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static final finalStaticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() var instanceVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() final finalInstanceVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + + @augmented() + static var staticVariable1 = "Original"; + @augmented() + static final finalStaticVariable1 = "Original"; + @augmented() + final finalInstanceVariable1 = "Original"; + + @augmented() + augment static var staticVariable1; + @augmented() + augment static final finalStaticVariable1; + @augmented() + augment final finalInstanceVariable1; +} + +augment enum E { + e1; + + @augmented() augment static var staticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment static final finalStaticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment final finalInstanceVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static var staticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static final finalStaticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() final finalInstanceVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + @augmented() + static var staticVariable1 = "Original"; + @augmented() + static final finalStaticVariable1 = "Original"; + + @augmented() + augment static var staticVariable1; + @augmented() + augment static final finalStaticVariable1; +} + +augment extension Ext { + @augmented() augment static var staticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment static final finalStaticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static var staticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static final finalStaticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + @augmented() + static var staticVariable1 = "Original"; + @augmented() + static final finalStaticVariable1 = "Original"; + + @augmented() + augment static var staticVariable1; + @augmented() + augment static final finalStaticVariable1; +} + +augment extension type ET { + @augmented() augment static var staticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment static final finalStaticVariable1 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static var staticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() static final finalStaticVariable2 = "Augment"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelVariable); + print(finalTopLevelVariable); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A04_t37.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A04_t37.dart new file mode 100644 index 0000000000..85525cf349 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A04_t37.dart @@ -0,0 +1,233 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting functions: Inside an augmenting function body (including +/// factory constructors but not generative constructors) `augmented` refers +/// to the augmented function. Tear-offs are not allowed, and this function +/// must immediately be invoked. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting function has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +const augmented = 0; + +@augmented +void topLevelFunction() {} + +@augmented +augment void topLevelFunction() {} + +class C { + C(); + @augmented + factory C.f1() => C(); + @augmented + static void staticMethod1() {} + @augmented + void instanceMethod1() {} + + @augmented + augment factory C.f1(); + @augmented + augment static void staticMethod1(); + @augmented + augment void instanceMethod1(); +} + +augment class C { + @augmented augment factory C.f1() => C(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented factory C.f2() => C(); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment static void staticMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment void instanceMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented static void staticMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented void instanceMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + @augmented + static void staticMethod1() {} + @augmented + void instanceMethod1() {} + + @augmented + augment static void staticMethod1(); + @augmented + augment void instanceMethod1(); +} + +augment mixin M { + @augmented augment static void staticMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment void instanceMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented static void staticMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented void instanceMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + @augmented + static void staticMethod1() {} + @augmented + void instanceMethod1() {} + + @augmented + augment static void staticMethod1(); + @augmented + augment void instanceMethod1(); +} + +augment enum E { + e1; + @augmented augment static void staticMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment void instanceMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented static void staticMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented void instanceMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} +extension Ext on A { + @augmented + static void staticMethod1() {} + @augmented + void instanceMethod1() {} + + @augmented + augment static void staticMethod1(); + @augmented + augment void instanceMethod1(); +} + +augment extension Ext { + @augmented augment static void staticMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment void instanceMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented static void staticMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented void instanceMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + @augmented + factory ET.f() => ET(0); + @augmented + static void staticMethod1() {} + @augmented + void instanceMethod1() {} + + @augmented + augment static void staticMethod1(); + @augmented + augment void instanceMethod1(); +} + +augment extension type ET { + @augmented augment factory ET.f1() => ET(1); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented factory ET.f2() => ET(2); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment static void staticMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented augment void instanceMethod1() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented static void staticMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + + @augmented void instanceMethod2() {} +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(topLevelFunction); + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A05_t26.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A05_t26.dart new file mode 100644 index 0000000000..ab6c1ee286 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A05_t26.dart @@ -0,0 +1,130 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting operators: When augmenting an operator, `augmented` refers to +/// the augmented operator method, which must be immediately invoked using +/// function call syntax. For example when augmenting `operator +` you would +/// use `augmented(1)` to call the augmented operator, and when augmenting +/// `operator []=` you would use the `augmented(key, value)` syntax. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting operator has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class augmented { + const augmented(); +} + +class C { + @augmented() + String operator +(Object? other) => "Original + $other"; + + @augmented() + augment String operator +(Object? other); +} + +augment class C { + @augmented() augment String operator +(Object? other) => "Augment + $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String operator -(Object? other) => "Augment - $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M { + @augmented() + String operator +(Object? other) => "Original + $other"; + + @augmented() + augment String operator +(Object? other); +} + +augment mixin M { + @augmented() augment String operator +(Object? other) => "Augment + $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String operator -(Object? other) => "Augment - $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + e0; + @augmented() + String operator +(Object? other) => "Original + $other"; + + @augmented() + augment String operator +(Object? other); +} + +augment enum E { + e1; + @augmented() augment String operator +(Object? other) => "Augment + $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String operator -(Object? other) => "Augment - $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class A {} + +extension Ext on A { + @augmented() + String operator +(Object? other) => "Original + $other"; + + @augmented() + augment String operator +(Object? other); +} + +augment extension Ext { + @augmented() augment String operator +(Object? other) => "Augment + $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String operator -(Object? other) => "Augment - $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int _) { + @augmented() + String operator +(Object? other) => "Original + $other"; + + @augmented() + augment String operator +(Object? other); +} + +augment extension type ET { + @augmented() augment String operator +(Object? other) => "Augment + $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() String operator -(Object? other) => "Augment - $other"; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(M); + print(E); + print(A); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A06_t05.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A06_t05.dart new file mode 100644 index 0000000000..fa477b6a86 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A06_t05.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting enum values: When augmenting an enum value, `augmented` has no +/// meaning and is not allowed. +/// +/// @description Checks that it is a compile-time error if in an augmenting +/// scope an augmenting enum value has a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +const augmented = 0; + +enum E { + @augmented + e0, + @augmented + augment e0; +} + +augment enum E { + @augmented augment e0, +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented e1; +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t30.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t30.dart new file mode 100644 index 0000000000..d1f1bdef5e --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t30.dart @@ -0,0 +1,90 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting non-redirecting generative constructors: Unlike other +/// functions, `augmented` has no special meaning in non-redirecting +/// generative constructors. It is still a reserved word inside the body of +/// these constructors, since they are within the scope of an augmenting +/// declaration. +/// +/// @description Checks that it is a compile-time error for an augmenting +/// non-redirecting generative constructor to use a metadata named `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +const augmented = 1; + +class C { + int id; + C(this.id); + C.foo(this.id); +} + +augment class C { + @augmented augment C(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment C.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented C.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + a0(0), a1.foo(1); + final int id; + const E(this.id); + const E.foo(this.id); +} + +augment enum E { + a2.bar(2); + @augmented augment const E(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment const E.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented const E.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int id) { + ET.foo(this.id); +} + +augment extension type ET { + @augmented augment ET(int id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented augment ET.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented ET.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(E); + print(ET); +} diff --git a/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t31.dart b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t31.dart new file mode 100644 index 0000000000..2e0a7879d0 --- /dev/null +++ b/LanguageFeatures/Augmentation-libraries/augmented_expression_A11_t31.dart @@ -0,0 +1,113 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion The exact result of an `augmented` expression depends on what is +/// being augmented, but it generally follows the same rules as any normal +/// identifier: +/// ... +/// - Augmenting non-redirecting generative constructors: Unlike other +/// functions, `augmented` has no special meaning in non-redirecting +/// generative constructors. It is still a reserved word inside the body of +/// these constructors, since they are within the scope of an augmenting +/// declaration. +/// +/// @description Checks that it is a compile-time error if in augmenting scope +/// an augmenting non-redirecting generative constructor has a metadata named +/// `augmented`. +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=macros + +class augmented { + const augmented(); +} + +class C { + int id; + @augmented() + C(this.id); + @augmented() + C.foo(this.id); + + @augmented() + augment C(this.id); + @augmented() + augment C.foo(this.id); +} + +augment class C { + @augmented() augment C(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment C.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() C.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E { + a0(0), a1.foo(1); + final int id; + @augmented() + const E(this.id); + @augmented() + const E.foo(this.id); + + @augmented() + augment const E(this.id); + @augmented() + augment const E.foo(this.id); +} + +augment enum E { + a2.bar(2); + @augmented() augment const E(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment const E.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() const E.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +extension type ET(int id) { + @augmented() + ET.foo(this.id); + + @augmented() + augment ET.new(int id); + @augmented() + augment ET.foo(this.id); +} + +augment extension type ET { + @augmented() augment ET(int id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() augment ET.foo(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + @augmented() ET.bar(this.id); +// ^^^^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(C); + print(E); + print(ET); +}