Skip to content

Commit a4f8892

Browse files
authored
#3182. Update augmenting_functions_A02_*.dart test (#3426)
Update `augmenting_functions_A02_*.dart` test
1 parent af8e9b9 commit a4f8892

24 files changed

+245
-1451
lines changed

LanguageFeatures/Augmentations/augmenting_functions_A02_t01.dart

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,65 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion Inside the augmenting function’s body, a special `augmented(…)`
6-
/// expression may be used to execute the augmented function body. That
7-
/// expression takes an argument list matching the augmented function's
8-
/// parameter list, and it has the same return type as the enclosing function.
5+
/// @assertion More precisely, a function or constructor declaration
6+
/// (introductory or augmenting) is incomplete if all of:
7+
/// - It has no body. That means no `{ ... }` or `=> ...;` but only `;`.
8+
/// - The function is not marked external. An external function is considered to
9+
/// have a body, just not one that is visible as Dart code.
10+
/// - There is no redirection, initializer list, initializing formals, field
11+
/// parameters, or super parameters. Obviously, this only applies to
12+
/// constructor declarations.
913
///
10-
/// @description Checks that inside an augmentation body of a top-level function
11-
/// `augmented()` expression executes the original function body.
14+
/// If a declaration is not incomplete then it is complete.
15+
///
16+
/// It's a compile-time error if an augmentation is complete and any declaration
17+
/// before it in the augmentation chain is also complete.
18+
///
19+
/// @description Checks that it is a compile-time error to add a body to an
20+
/// already complete top level function.
1221
/// @author sgrekhov22@gmail.com
1322
14-
// SharedOptions=--enable-experiment=macros
15-
16-
import '../../Utils/expect.dart';
17-
part 'augmenting_functions_A02_t01_lib.dart';
23+
// SharedOptions=--enable-experiment=augmentations
1824

19-
String _log = "";
25+
void topLevelFunction1() {}
2026

21-
void clearLog() {
22-
_log = "";
23-
}
24-
25-
String topLevelFunction1() {
26-
_log += "topLevelFunction1();";
27-
return "Original;";
28-
}
27+
augment void topLevelFunction1() {}
28+
// ^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
2931

30-
String topLevelFunction2(String v) {
31-
_log += "topLevelFunction2($v);";
32-
return "Original v=$v;";
33-
}
32+
void topLevelFunction2(String v) {}
3433

35-
String topLevelFunction3(String v1, [String v2 = "v2 def"]) {
36-
_log += "topLevelFunction3($v1, [$v2]);";
37-
return "Original v1=$v1, [v2=$v2];";
38-
}
34+
augment void topLevelFunction2(String v) {}
35+
// ^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
3938

40-
String topLevelFunction4(String v1, {String v2 = "v2 def"}) {
41-
_log += "topLevelFunction4($v1, {$v2});";
42-
return "Original v1=$v1, {v2=$v2};";
43-
}
39+
void topLevelFunction3(String v1, [String v2 = "v2 def"]) {}
4440

45-
String topLevelFunction5(String v1, {required String v2}) {
46-
_log += "topLevelFunction5($v1, {required $v2});";
47-
return "Original v1=$v1, {required v2=$v2};";
48-
}
41+
augment void topLevelFunction3(String v1, [String v2 = "v2 def"]) {}
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
4945

50-
main() {
51-
Expect.equals("augment;", topLevelFunction1());
52-
Expect.equals("topLevelFunction1();Original;augmented;", _log);
53-
clearLog();
46+
void topLevelFunction4(String v1, {String v2 = "v2 def"}) {}
5447

55-
Expect.equals("augment v=A;", topLevelFunction2("A"));
56-
Expect.equals("topLevelFunction2(A);Original v=A;augmented;", _log);
57-
clearLog();
48+
augment void topLevelFunction4(String v1, {String v2 = "v2 def"}) {}
49+
// ^
50+
// [analyzer] unspecified
51+
// [cfe] unspecified
5852

59-
Expect.equals("augment v1=B, [v2=C]", topLevelFunction3("B", "C"));
60-
Expect.equals("topLevelFunction3(B, [C]);Original v1=B, [v2=C];augmented;",
61-
_log);
62-
clearLog();
53+
void topLevelFunction5(String v1, {required String v2}) {}
6354

64-
Expect.equals("augment v1=D, {v2=E}", topLevelFunction4("D", v2: "E"));
65-
Expect.equals("topLevelFunction4(D, {E});Original v1=D, {v2=E};augmented;",
66-
_log);
67-
clearLog();
55+
augment void topLevelFunction5(String v1, {required String v2}) {}
56+
// ^
57+
// [analyzer] unspecified
58+
// [cfe] unspecified
6859

69-
Expect.equals("augment v1=F, {required v2=G}",
70-
topLevelFunction5("F", v2: "G"));
71-
Expect.equals(
72-
"topLevelFunction5(F, {required G});Original v1=F, {required v2=G};" +
73-
"augmented;", _log);
60+
main() {
61+
print(topLevelFunction1);
62+
print(topLevelFunction2);
63+
print(topLevelFunction3);
64+
print(topLevelFunction4);
65+
print(topLevelFunction5);
7466
}

LanguageFeatures/Augmentations/augmenting_functions_A02_t01_lib.dart

Lines changed: 0 additions & 46 deletions
This file was deleted.

LanguageFeatures/Augmentations/augmenting_functions_A02_t02.dart

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,89 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion Inside the augmenting function’s body, a special `augmented(…)`
6-
/// expression may be used to execute the augmented function body. That
7-
/// expression takes an argument list matching the augmented function's
8-
/// parameter list, and it has the same return type as the enclosing function.
5+
/// @assertion More precisely, a function or constructor declaration
6+
/// (introductory or augmenting) is incomplete if all of:
7+
/// - It has no body. That means no `{ ... }` or `=> ...;` but only `;`.
8+
/// - The function is not marked external. An external function is considered to
9+
/// have a body, just not one that is visible as Dart code.
10+
/// - There is no redirection, initializer list, initializing formals, field
11+
/// parameters, or super parameters. Obviously, this only applies to
12+
/// constructor declarations.
913
///
10-
/// @description Checks that inside an augmentation body of a static method
11-
/// `augmented()` expression executes the original method body. Test a class.
14+
/// If a declaration is not incomplete then it is complete.
15+
///
16+
/// It's a compile-time error if an augmentation is complete and any declaration
17+
/// before it in the augmentation chain is also complete.
18+
///
19+
/// @description Checks that it is a compile-time error to add a body to an
20+
/// already complete static method.
1221
/// @author sgrekhov22@gmail.com
1322
14-
// SharedOptions=--enable-experiment=macros
23+
// SharedOptions=--enable-experiment=augmentations
1524

16-
import '../../Utils/expect.dart';
17-
part 'augmenting_functions_A02_t02_lib.dart';
25+
class C {
26+
static void staticMethod() {}
27+
}
1828

19-
String _log = "";
29+
augment class C {
30+
augment static void staticMethod() {}
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
}
2035

21-
void clearLog() {
22-
_log = "";
36+
mixin M {
37+
static void staticMethod() {}
2338
}
2439

25-
class C {
26-
static String staticMethod1() {
27-
_log += "staticMethod1();";
28-
return "Original;";
29-
}
40+
augment mixin M {
41+
augment static void staticMethod() {}
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
}
3046

31-
static String staticMethod2(String v) {
32-
_log += "staticMethod2($v);";
33-
return "Original v=$v;";
34-
}
47+
enum E {
48+
e0;
49+
static void staticMethod() {}
50+
}
3551

36-
static String staticMethod3(String v1, [String v2 = "v2 def"]) {
37-
_log += "staticMethod3($v1, [$v2]);";
38-
return "Original v1=$v1, [v2=$v2];";
39-
}
52+
augment enum E {
53+
;
54+
augment static void staticMethod() {}
55+
// ^
56+
// [analyzer] unspecified
57+
// [cfe] unspecified
58+
}
4059

41-
static String staticMethod4(String v1, {String v2 = "v2 def"}) {
42-
_log += "staticMethod4($v1, {$v2});";
43-
return "Original v1=$v1, {v2=$v2};";
44-
}
60+
class A {}
4561

46-
static String staticMethod5(String v1, {required String v2}) {
47-
_log += "staticMethod5($v1, {required $v2});";
48-
return "Original v1=$v1, {required v2=$v2};";
49-
}
62+
extension Ext on A {
63+
static void staticMethod() {}
5064
}
5165

52-
main() {
53-
Expect.equals("augment;", C.staticMethod1());
54-
Expect.equals("staticMethod1();Original;augmented;", _log);
55-
clearLog();
56-
57-
Expect.equals("augment v=A;", C.staticMethod2("A"));
58-
Expect.equals("staticMethod2(A);Original v=A;augmented;", _log);
59-
clearLog();
66+
augment extension Ext {
67+
augment static void staticMethod() {}
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
}
6072

61-
Expect.equals("augment v1=B, [v2=C]", C.staticMethod3("B", "C"));
62-
Expect.equals("staticMethod3(B, [C]);Original v1=B, [v2=C];augmented;", _log);
63-
clearLog();
73+
extension type ET(int _) {
74+
static void staticMethod() {}
75+
}
6476

65-
Expect.equals("augment v1=D, {v2=E}", C.staticMethod4("D", v2: "E"));
66-
Expect.equals("staticMethod4(D, {E});Original v1=D, {v2=E};augmented;", _log);
67-
clearLog();
77+
augment extension type ET {
78+
augment static void staticMethod() {}
79+
// ^
80+
// [analyzer] unspecified
81+
// [cfe] unspecified
82+
}
6883

69-
Expect.equals("augment v1=F, {required v2=G}", C.staticMethod5("F", v2: "G"));
70-
Expect.equals(
71-
"staticMethod5(F, {required G});Original v1=F, {required v2=G};" +
72-
"augmented;", _log);
84+
main() {
85+
print(C);
86+
print(M);
87+
print(E);
88+
print(A);
89+
print(ET);
7390
}

LanguageFeatures/Augmentations/augmenting_functions_A02_t02_lib.dart

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)