|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
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. |
9 | 13 | /// |
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. |
12 | 21 | /// @author sgrekhov22@gmail.com |
13 | 22 |
|
14 | | -// SharedOptions=--enable-experiment=macros |
15 | | - |
16 | | -import '../../Utils/expect.dart'; |
17 | | -part 'augmenting_functions_A02_t01_lib.dart'; |
| 23 | +// SharedOptions=--enable-experiment=augmentations |
18 | 24 |
|
19 | | -String _log = ""; |
| 25 | +void topLevelFunction1() {} |
20 | 26 |
|
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 |
29 | 31 |
|
30 | | -String topLevelFunction2(String v) { |
31 | | - _log += "topLevelFunction2($v);"; |
32 | | - return "Original v=$v;"; |
33 | | -} |
| 32 | +void topLevelFunction2(String v) {} |
34 | 33 |
|
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 |
39 | 38 |
|
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"]) {} |
44 | 40 |
|
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 |
49 | 45 |
|
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"}) {} |
54 | 47 |
|
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 |
58 | 52 |
|
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}) {} |
63 | 54 |
|
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 |
68 | 59 |
|
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); |
74 | 66 | } |
0 commit comments