@@ -15,6 +15,10 @@ information about the process, including in their change logs.
15
15
[ 1 ] : https://github.com/dart-lang/language/blob/master/working/1426-extension-types/feature-specification-views.md
16
16
[ 2 ] : https://github.com/dart-lang/language/blob/master/working/extension_structs/overview.md
17
17
18
+ 2023.10.31
19
+ - Simplify the rules about the relationship between extension types and the
20
+ types ` Object ` and ` Object? ` .
21
+
18
22
2023.10.25
19
23
- Allow an extension type to have ` implements T ` where ` T ` is a
20
24
supertype of the representation type (the old rule only allows
@@ -719,7 +723,7 @@ _not_ eliminated by the existence of other declarations (of any kind) named
719
723
` _n ` in the same library.
720
724
721
725
Conversely, the existence of an extension type with a representation
722
- variable with a private name ` _n ` does not eliminate promotion of
726
+ variable with a private name ` _n ` does not eliminate promotion of
723
727
any private instance variables named ` _n ` of a class, mixin, enum, or mixin
724
728
class in the same library.
725
729
@@ -976,24 +980,18 @@ declaration itself, or we're talking about a particular generic
976
980
instantiation of an extension type. * For non-generic extension type
977
981
declarations, the representation type is the same in either case.*
978
982
979
- Let ` V ` be an extension type of the form
980
- <code >Name\< T<sub >1</sub >, .. T<sub >s</sub >> ; </code >, and let
981
- ` R ` be the corresponding instantiated representation type. If ` R ` is
982
- non-nullable then ` V ` is a proper subtype of ` Object ` , and ` V ` is
983
- non-nullable. Otherwise, ` V ` is a proper subtype of ` Object? ` , and
984
- ` V ` is potentially nullable.
983
+ An extension type ` V ` is a proper subtype of ` Object? ` . It is potentially
984
+ non-nullable, unless it implements ` Object ` or a subtype thereof
985
+ * (as described in the section about extension types with superinterfaces)* .
985
986
986
987
* That is, an expression of an extension type can be assigned to a top type
987
- (like all other expressions), and if the representation type is
988
- non-nullable then it can also be assigned to ` Object ` . Non-extension types
989
- (except bottom types and ` dynamic ` ) cannot be assigned to extension types
990
- without an explicit cast. Similarly, null cannot be assigned to an
991
- extension type without an explicit cast, even in the case where the
992
- representation type is nullable (even better: don't use a cast, call a
993
- constructor instead). Another consequence of the fact that the extension
994
- type is potentially non-nullable is that it is an error to have an instance
995
- variable whose type is an extension type, and then relying on implicit
996
- initialization to null.*
988
+ (like all other expressions). Non-extension types (except bottom types and
989
+ ` dynamic ` ) cannot be assigned to extension types without an explicit cast.
990
+ Similarly, the null object cannot be assigned to an extension type without
991
+ an explicit cast (or if it has a static type which is an extension type,
992
+ e.g., ` E(null) ` ). Since an extension type is potentially non-nullable, an
993
+ instance variable whose type is an extension type must be initialized. It
994
+ will not be implicitly initialized to null.*
997
995
998
996
In the body of a member of an extension type declaration _ DV_ named
999
997
` Name ` and declaring the type parameters
@@ -1136,10 +1134,6 @@ Assume that _DV_ is an extension type declaration named `Name`, and
1136
1134
` V1 ` occurs as one of the ` <type> ` s in the ` <interfaces> ` of _ DV_ . In
1137
1135
this case we say that ` V1 ` is a _ superinterface_ of _ DV_ .
1138
1136
1139
- If _ DV_ does not include an ` <interfaces> ` clause then _ DV_ has
1140
- ` Object? ` or ` Object ` as a direct superinterface, according to the subtype
1141
- relation which was specified earlier.
1142
-
1143
1137
A compile-time error occurs if ` V1 ` is a type name or a parameterized type
1144
1138
which occurs as a superinterface in an extension type declaration _ DV_ , and
1145
1139
` V1 ` denotes a non-extension type which is not a supertype of the
@@ -1303,12 +1297,12 @@ rather than from `Object`)*.
1303
1297
1304
1298
* This change is needed because some extension types are subtypes of
1305
1299
` Object? ` and not subtypes of ` Object ` , and they need to have a
1306
- well-defined depth. Note that the depth of an extension type can be
1307
- determined by its actual type arguments, if any, because type parameters of
1308
- the extension type may occur in its representation type. In particular, the
1309
- depth of an extension type is a property of the type itself, and it is not
1310
- always possible to determine the depth from the associated extension type
1311
- declaration .*
1300
+ well-defined depth. We could define the depth to be zero for ` Object ` , for
1301
+ ` Null ` , and for every extension type that has no ` implements ` clause, but
1302
+ in that case we no longer have a guarantee that the sets of superinterfaces
1303
+ with the same maximal depth that the Dart 1 least upper bound algorithm
1304
+ uses will have at least one singleton set. All in all, it's simpler if we
1305
+ preserve the property that the superinterface graph has a single root .*
1312
1306
1313
1307
1314
1308
## Dynamic Semantics of Extension Types
@@ -1377,21 +1371,18 @@ used as an expression *(also known as the ultimate representation type)*.
1377
1371
### Summary of Typing Relationships
1378
1372
1379
1373
* Here is an overview of the subtype relationships of an extension type ` V0 `
1380
- with instantiated representation type ` R ` and instantiated superinterface
1381
- types ` V1 .. Vk ` , as well as other typing relationships involving ` V0 ` :*
1374
+ with instantiated representation type ` R ` (whose extension type erasure is ` R0 ` )
1375
+ and instantiated superinterface types ` V1 .. Vk ` , as well as other typing
1376
+ relationships involving ` V0 ` :*
1382
1377
1383
1378
- * ` V0 ` is a proper subtype of ` Object? ` .*
1384
- - * ` V0 ` is a supertype of ` Never ` .*
1385
- - * If ` R ` is a non-nullable type then ` V0 ` is a proper subtype of
1386
- ` Object ` , and a non-nullable type.*
1379
+ - * ` V0 ` is a proper supertype of ` Never ` .*
1387
1380
- * ` V0 ` is a proper subtype of each of ` V1 .. Vk ` .*
1388
- - * At run time, the type ` V0 ` is identical to the type ` R ` . In
1389
- particular, ` o is V0 ` and ` o as V0 ` have the same dynamic
1390
- semantics as ` o is R ` respectively ` o as R ` , and
1391
- ` t1 == t2 ` evaluates to true if ` t1 ` is a ` Type ` that reifies
1392
- ` V0 ` and ` t2 ` reifies ` R ` , and the equality also holds if
1393
- ` t1 ` and ` t2 ` reify types where ` V0 ` and ` R ` occur as subterms
1394
- (e.g., ` List<V0> ` is equal to ` List<R> ` ).*
1381
+ - * Let ` R0 ` be the extension type erasure of ` V0 ` . At run time, the type
1382
+ ` V0 ` has the same representation and semantics as ` R0 ` . In particular,
1383
+ they behave identically with respect to ` is ` , ` is! ` , ` as ` , and ` == ` ,
1384
+ both when ` V0 ` and ` R0 ` are used as types, and when they occur as
1385
+ subterms of another type.
1395
1386
1396
1387
1397
1388
## Discussion
0 commit comments