Skip to content

Commit 913b81e

Browse files
authored
[extension-types] Add rules about non-extension types (#3276)
Specify that extension type members can be external, but not abstract. Generalize the covariance subtype rule to include extension types. Modify the notion of the 'depth' of a type to support extension types (because they do not necessarily have `Object` in their superinterface graph), hence enabling `UP` to handle extension types.
1 parent 39efdc7 commit 913b81e

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

accepted/future-releases/extension-types/feature-specification.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ information about the process, including in their change logs.
1515
[1]: https://github.com/dart-lang/language/blob/master/working/1426-extension-types/feature-specification-views.md
1616
[2]: https://github.com/dart-lang/language/blob/master/working/extension_structs/overview.md
1717

18+
2023.08.17
19+
- Add covariance subtype rule for extension types. Add rule that it is an
20+
error for an extension type member to be abstract. Mention that it is
21+
allowed for extension type members to be external. Adjust the notion of
22+
the 'depth' of a type such that `UP` can be used with extension types.
23+
1824
2023.07.13
1925
- Revise many details, in particular the management of ambiguities
2026
involving extension type members and non-extension type members.
@@ -688,6 +694,19 @@ Member Conflicts' occur as well in an extension type declaration.
688694
and has an instance member named `V`, and it is a compile-time error if it
689695
has a type parameter named `X` and it has an instance member named `X`.*
690696

697+
It is a compile-time error if a member declaration in an extension type
698+
declaration is abstract.
699+
700+
*Extension type member invocations and tear-offs are always statically
701+
resolved, and abstract members only make sense in the case where the given
702+
member is resolved at run time.*
703+
704+
*It is not an error for an extension type member to have the modifier
705+
`external`. As usual, an implementation can report a compile-time error for
706+
external declarations, e.g., if they are not bound to an implementation,
707+
and the method by which they are bound to an implementation is tool
708+
specific.*
709+
691710
Assume that
692711
<code>T<sub>1</sub>, .. T<sub>s</sub></code>
693712
are types, and `V` resolves to an extension type declaration of the
@@ -1178,6 +1197,45 @@ all members of `V1, .. Vk` that are not redeclared by a declaration in _DV_
11781197
can be invoked on a receiver of the type introduced by _DV_.*
11791198

11801199

1200+
### Changes to other types and subtyping
1201+
1202+
The previous sections have introduced some subtype relationships involving
1203+
extension types. This section adds further relationships where extension
1204+
types occur more indirectly.
1205+
1206+
*For instance, earlier sections stated that every extension type is a
1207+
subtype of the top types (like `Object?`), and that `implements` introduces
1208+
a subtype relationship for extension types. Moreover:*
1209+
1210+
Assume that `E` denotes an extension type that takes `k` type arguments.
1211+
Corresponding to the subtype rule about covariance for classes, a rule is
1212+
introduced which makes <code>E\<S<sub>1</sub> .. S<sub>k</sub>></code> a
1213+
subtype of <code>E\<T<sub>1</sub> .. T<sub>k</sub>></code> if
1214+
<code>S<sub>j</sub></code> is a subtype of <code>T<sub>j</sub></code> for
1215+
each `j` in 1 .. k.
1216+
1217+
*For example, `E<int>` is a subtype of `E<Object>` because `int` is a
1218+
subtype of `Object`, also in the case where `E` is an extension type.*
1219+
1220+
The Dart 1 algorithm which is used to compute the standard upper bound of
1221+
two distinct interface types will work in the same way as it does today,
1222+
albeit on a slightly different superinterface graph:
1223+
1224+
For the purpose of this algorithm, we consider `Object?` to be a
1225+
superinterface of `Null` and `Object`, and the path lengths mentioned in
1226+
the algorithm will increase by one *(because they start from `Object?`
1227+
rather than from `Object`)*.
1228+
1229+
*This change is needed because some extension types are subtypes of
1230+
`Object?` and not subtypes of `Object`, and they need to have a
1231+
well-defined depth. Note that the depth of an extension type can be
1232+
determined by its actual type arguments, if any, because type parameters of
1233+
the extension type may occur in its representation type. In particular, the
1234+
depth of an extension type is a property of the type itself, and it is not
1235+
always possible to determine the depth from the associated extension type
1236+
declaration.*
1237+
1238+
11811239
## Dynamic Semantics of Extension Types
11821240

11831241
For any given syntactic construct which has been characterized as an

0 commit comments

Comments
 (0)