Skip to content

Commit

Permalink
#2559. Add metadata tests. Part 1. (#3017)
Browse files Browse the repository at this point in the history
Add metadata tests. Part 1.
  • Loading branch information
sgrekhov authored Dec 17, 2024
1 parent 3e8abbe commit d23755b
Show file tree
Hide file tree
Showing 8 changed files with 1,267 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 [email protected]
// 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);
}
Original file line number Diff line number Diff line change
@@ -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 [email protected]
// 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);
}
Loading

0 comments on commit d23755b

Please sign in to comment.