|
2 | 2 |
|
3 | 3 | Author: rnystrom@google.com, jakemac@google.com, lrn@google.com |
4 | 4 |
|
5 | | -Version: 1.38 (see [Changelog](#Changelog) at end) |
| 5 | +Version: 1.40 (see [Changelog](#Changelog) at end) |
6 | 6 |
|
7 | 7 | Experiment flag: augmentations |
8 | 8 |
|
@@ -1003,6 +1003,57 @@ the combined declaration.* |
1003 | 1003 |
|
1004 | 1004 | [analyzer package]: https://pub.dev/packages/analyzer |
1005 | 1005 |
|
| 1006 | +### Compile errors with augmentations |
| 1007 | + |
| 1008 | +Prior to augmentations, the definition of a semantic entity is produced by a |
| 1009 | +single syntactic declaration. That allows the language specification to refer to |
| 1010 | +those entities interchangeably. With augmentations, that is no longer the case. |
| 1011 | +A single semantic entity may be the product of multiple syntactic declarations |
| 1012 | +(an introductory and any number of augmentations). This raises the question of |
| 1013 | +whether existing compile errors apply to syntactic declarations or semantic |
| 1014 | +definitions. For example, the specification says: |
| 1015 | + |
| 1016 | +> It is a compile-time error if two elements in the type list of the |
| 1017 | +> `implements` clause of a class `C` specifies the same type `T`. |
| 1018 | +
|
| 1019 | +Thus this is an error: |
| 1020 | + |
| 1021 | +```dart |
| 1022 | +class C implements I, I {} |
| 1023 | +``` |
| 1024 | + |
| 1025 | +But what about: |
| 1026 | + |
| 1027 | +```dart |
| 1028 | +class C implements I {} |
| 1029 | +
|
| 1030 | +augment class C implements I {} |
| 1031 | +``` |
| 1032 | + |
| 1033 | +Each syntactic declaration of `C` only mentions the interface once. But the |
| 1034 | +resulting definition produced by applying augmentations has an `implements` |
| 1035 | +clause with `I` in it twice. To which entity does the error apply? |
| 1036 | + |
| 1037 | +The general rule is that **compile-time errors apply to semantic definitions |
| 1038 | +whenever possible.** In other words, if the library is syntactically well-formed |
| 1039 | +enough that augmentations *can* be applied, then they should be. And if doing so |
| 1040 | +eliminates what would otherwise be a compile-time error, then that error should |
| 1041 | +not be reported. |
| 1042 | + |
| 1043 | +In the example above, there is an error because the resulting definition does |
| 1044 | +have the same interface twice in the `implements` clause. *(Though note that |
| 1045 | +[#4542](https://github.com/dart-lang/language/issues/4542) tracks whether we |
| 1046 | +want to change this specific error.)* |
| 1047 | + |
| 1048 | +The motivation for this principle is that reorganizing code into or out of |
| 1049 | +augmentations shouldn't affect the errors that are reported as much as possible. |
| 1050 | +Augmentations are a syntactic tool for organizing code, but what the user cares |
| 1051 | +about -- and what static analysis should thus focus on -- is the semantics of |
| 1052 | +the resulting definitions. Also, in most cases the error relies on semantic |
| 1053 | +information that isn't even well defined for syntactic entities and is only |
| 1054 | +known from the resolved semantic definition which can't be produced without |
| 1055 | +applying augmentations. |
| 1056 | + |
1006 | 1057 | ## Dynamic semantics |
1007 | 1058 |
|
1008 | 1059 | The application of augmentation declarations to an augmented declaration |
@@ -1216,6 +1267,11 @@ and assume the third point is always true. |
1216 | 1267 |
|
1217 | 1268 | ## Changelog |
1218 | 1269 |
|
| 1270 | +### 1.40 |
| 1271 | + |
| 1272 | +* Clarify how applying augmentations interacts with compile-time errors |
| 1273 | + (#3690). |
| 1274 | + |
1219 | 1275 | ### 1.39 |
1220 | 1276 |
|
1221 | 1277 | * Non-semantic copy editing. Remove some redundant specification. Clarify |
|
0 commit comments