Skip to content

Commit a328bfa

Browse files
authored
Merge branch 'main' into spec_extension_type_shadow_nov23
2 parents e49d0e4 + 2edfa84 commit a328bfa

File tree

2 files changed

+37
-42
lines changed

2 files changed

+37
-42
lines changed

accepted/2.17/enhanced-enums/feature-specification.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ It is a **compile-time error** to refer to a declared or default generative cons
6464
* As the target of a redirecting generative constructor of the same `enum` declaration (`: this(...);`/`: this.targetName(...);`), or
6565
* Implicitly in the enum value declarations of the same `enum` (`enumValueName(args)`/`enumValueName.targetName(args)`).
6666

67-
_No-one is allowed to invoke a generative constructor and create an instance of the `enum` other than the enumerated enum values.
68-
That also means that a redirecting *factory* constructor cannot redirect to a generative constructor of an `enum`,
69-
and therefore no factory constructor of an `enum` declaration can be `const`, because a `const` factory constructor must redirect to a generative constructor._
67+
_No-one is allowed to invoke a generative constructor and create an instance of the `enum` other than the enumerated enum values._
68+
69+
It is a **compile-time error** if the constructor implicitly invoked by an enumerated enum value declaration is a factory constructor.
70+
71+
_A redirecting factory constructor can redirect to a generative constructor of an `extension type`, which may in turn return one of the existing values of that `enum`. This must be an error, because the enumerated values of an `enum` declaration must be distinct._
7072

7173
It's a **compile-time error** if the enum declaration contains a static or instance member declaration with the name `values`, or if the superclass or any superinterface of the enum declaration has an interface member named `values`. _A `values` static constant member will be provided for the class, this restriction ensures that there is no conflict with that declaration._
7274

@@ -460,3 +462,5 @@ There is a chance that people will start using `enum` declarations to declare si
460462
1.7, 2022-02-16: Disallow overriding `operator==` and `hashCode` too.
461463
1.8, 2022-03-08: Make it explicit that an enum constructor cannot use the new super-parameters.
462464
1.9, 2023-01-13: Adjust the grammar to allow enum entry using `new` to specify a constructor.
465+
1.10, 2023-11-10: Add an error about factory constructors: They can not be used
466+
to create enum values.

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

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ information about the process, including in their change logs.
2020
setter with the same basename, and vice versa. This eliminates a
2121
method/setter conflict that would otherwise be impossible to avoid.
2222

23+
2023.10.31
24+
- Simplify the rules about the relationship between extension types and the
25+
types `Object` and `Object?`.
26+
2327
2023.10.25
2428
- Allow an extension type to have `implements T` where `T` is a
2529
supertype of the representation type (the old rule only allows
@@ -757,7 +761,7 @@ _not_ eliminated by the existence of other declarations (of any kind) named
757761
`_n` in the same library.
758762

759763
Conversely, the existence of an extension type with a representation
760-
variable with a private name `_n` does not eliminate promotion of
764+
variable with a private name `_n` does not eliminate promotion of
761765
any private instance variables named `_n` of a class, mixin, enum, or mixin
762766
class in the same library.
763767

@@ -1014,24 +1018,18 @@ declaration itself, or we're talking about a particular generic
10141018
instantiation of an extension type. *For non-generic extension type
10151019
declarations, the representation type is the same in either case.*
10161020

1017-
Let `V` be an extension type of the form
1018-
<code>Name\<T<sub>1</sub>, .. T<sub>s</sub>&gt;</code>, and let
1019-
`R` be the corresponding instantiated representation type. If `R` is
1020-
non-nullable then `V` is a proper subtype of `Object`, and `V` is
1021-
non-nullable. Otherwise, `V` is a proper subtype of `Object?`, and
1022-
`V` is potentially nullable.
1021+
An extension type `V` is a proper subtype of `Object?`. It is potentially
1022+
non-nullable, unless it implements `Object` or a subtype thereof
1023+
*(as described in the section about extension types with superinterfaces)*.
10231024

10241025
*That is, an expression of an extension type can be assigned to a top type
1025-
(like all other expressions), and if the representation type is
1026-
non-nullable then it can also be assigned to `Object`. Non-extension types
1027-
(except bottom types and `dynamic`) cannot be assigned to extension types
1028-
without an explicit cast. Similarly, null cannot be assigned to an
1029-
extension type without an explicit cast, even in the case where the
1030-
representation type is nullable (even better: don't use a cast, call a
1031-
constructor instead). Another consequence of the fact that the extension
1032-
type is potentially non-nullable is that it is an error to have an instance
1033-
variable whose type is an extension type, and then relying on implicit
1034-
initialization to null.*
1026+
(like all other expressions). Non-extension types (except bottom types and
1027+
`dynamic`) cannot be assigned to extension types without an explicit cast.
1028+
Similarly, the null object cannot be assigned to an extension type without
1029+
an explicit cast (or if it has a static type which is an extension type,
1030+
e.g., `E(null)`). Since an extension type is potentially non-nullable, an
1031+
instance variable whose type is an extension type must be initialized. It
1032+
will not be implicitly initialized to null.*
10351033

10361034
In the body of a member of an extension type declaration _DV_ named
10371035
`Name` and declaring the type parameters
@@ -1174,10 +1172,6 @@ Assume that _DV_ is an extension type declaration named `Name`, and
11741172
`V1` occurs as one of the `<type>`s in the `<interfaces>` of _DV_. In
11751173
this case we say that `V1` is a _superinterface_ of _DV_.
11761174

1177-
If _DV_ does not include an `<interfaces>` clause then _DV_ has
1178-
`Object?` or `Object` as a direct superinterface, according to the subtype
1179-
relation which was specified earlier.
1180-
11811175
A compile-time error occurs if `V1` is a type name or a parameterized type
11821176
which occurs as a superinterface in an extension type declaration _DV_, and
11831177
`V1` denotes a non-extension type which is not a supertype of the
@@ -1341,12 +1335,12 @@ rather than from `Object`)*.
13411335

13421336
*This change is needed because some extension types are subtypes of
13431337
`Object?` and not subtypes of `Object`, and they need to have a
1344-
well-defined depth. Note that the depth of an extension type can be
1345-
determined by its actual type arguments, if any, because type parameters of
1346-
the extension type may occur in its representation type. In particular, the
1347-
depth of an extension type is a property of the type itself, and it is not
1348-
always possible to determine the depth from the associated extension type
1349-
declaration.*
1338+
well-defined depth. We could define the depth to be zero for `Object`, for
1339+
`Null`, and for every extension type that has no `implements` clause, but
1340+
in that case we no longer have a guarantee that the sets of superinterfaces
1341+
with the same maximal depth that the Dart 1 least upper bound algorithm
1342+
uses will have at least one singleton set. All in all, it's simpler if we
1343+
preserve the property that the superinterface graph has a single root.*
13501344

13511345

13521346
## Dynamic Semantics of Extension Types
@@ -1415,21 +1409,18 @@ used as an expression *(also known as the ultimate representation type)*.
14151409
### Summary of Typing Relationships
14161410

14171411
*Here is an overview of the subtype relationships of an extension type `V0`
1418-
with instantiated representation type `R` and instantiated superinterface
1419-
types `V1 .. Vk`, as well as other typing relationships involving `V0`:*
1412+
with instantiated representation type `R` (whose extension type erasure is `R0`)
1413+
and instantiated superinterface types `V1 .. Vk`, as well as other typing
1414+
relationships involving `V0`:*
14201415

14211416
- *`V0` is a proper subtype of `Object?`.*
1422-
- *`V0` is a supertype of `Never`.*
1423-
- *If `R` is a non-nullable type then `V0` is a proper subtype of
1424-
`Object`, and a non-nullable type.*
1417+
- *`V0` is a proper supertype of `Never`.*
14251418
- *`V0` is a proper subtype of each of `V1 .. Vk`.*
1426-
- *At run time, the type `V0` is identical to the type `R`. In
1427-
particular, `o is V0` and `o as V0` have the same dynamic
1428-
semantics as `o is R` respectively `o as R`, and
1429-
`t1 == t2` evaluates to true if `t1` is a `Type` that reifies
1430-
`V0` and `t2` reifies `R`, and the equality also holds if
1431-
`t1` and `t2` reify types where `V0` and `R` occur as subterms
1432-
(e.g., `List<V0>` is equal to `List<R>`).*
1419+
- *Let `R0` be the extension type erasure of `V0`. At run time, the type
1420+
`V0` has the same representation and semantics as `R0`. In particular,
1421+
they behave identically with respect to `is`, `is!`, `as`, and `==`,
1422+
both when `V0` and `R0` are used as types, and when they occur as
1423+
subterms of another type.
14331424

14341425

14351426
## Discussion

0 commit comments

Comments
 (0)