Skip to content

Commit 961ed40

Browse files
authored
Allow extends Object and = Object with N for mixin classes. (#3022)
* Allow `extends Object` and `= Object with N` for mixin classes.
1 parent a620967 commit 961ed40

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

accepted/future-releases/class-modifiers/feature-specification.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Author: Bob Nystrom, Lasse Nielsen
44

55
Status: Accepted
66

7-
Version 1.7
7+
Version 1.8
88

99
Experiment flag: class-modifiers
1010

@@ -556,7 +556,7 @@ The grammar is:
556556
classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
557557
typeParameters? superclass? interfaces?
558558
'{' (metadata classMemberDeclaration)* '}'
559-
| classModifiers 'class' mixinApplicationClass
559+
| classModifiers 'mixin'? 'class' mixinApplicationClass
560560
561561
classModifiers ::= 'sealed'
562562
| 'abstract'? ('base' | 'interface' | 'final')?
@@ -597,10 +597,11 @@ they are declared as subtypes of as follow.
597597

598598
* A declaration *S* is _the declared superclass_ of a `class` declaration
599599
*D* iff:
600+
600601
* *D* has an `extends T` clause and `T` denotes *S*.
601602
* *D* has the form `... class ... = T with ...` and `T` denotes *S*.
602603

603-
_A type clause `T` denotes a declaration *S* if `T` of the from
604+
_A type clause `T` denotes a declaration *S* if `T` of the form
604605
<code>*id*</code> or <code>*id*\<typeArgs\></code>, and *id*
605606
is an identifier or qualified identifier which resolves to *S*,
606607
or which resolves to a type alias with a right-hand-side which
@@ -835,10 +836,23 @@ ensures that it can be used as both a `class` and a `mixin`.
835836
It's a compile-time error if a `mixin class` declaration:
836837
* has an `interface`, `final` or `sealed` modifier. _This is baked
837838
into the grammar, but it bears repeating._
838-
* has an `extends` clause,
839-
* has a `with` clause, or
839+
* does not have `Object` from `dart:core` as immediate superclass.
840840
* declares any non-trivial generative constructor.
841841
842+
A mixin class declaration has `Object` from `dart:core` as superclass iff it’s either:
843+
844+
* A mixin application class declaration where the declared
845+
superclass is the `Object` class from `dart:core`,
846+
and which has precisely one declared mixin.
847+
_E.g., `mixin class C = Object with M;`_
848+
* A non-mixin-application class declaration with no declared mixins,
849+
and either no declared superclass, or with a type denoting `Object` from `dart:core`
850+
as the declared superclass.
851+
_E.g., `mixin class C {}` or `mixin class C extends Object {}`_
852+
853+
_The mixin class declarations can also have interfaces, type parameters, _
854+
_and modifiers, but no `extends` or `with` clauses other than those shown here._
855+
842856
A *trivial generative constructor* is a generative constructor that:
843857
* Is not a redirecting constructor _(`Foo(...) : this.other(...);`),
844858
* declares no parameters (parameter list is precisely `()`),
@@ -885,9 +899,18 @@ mixin class C {
885899
int? x;
886900
}
887901
902+
mixin class C2 extends Object implements I {}
903+
904+
abstract base mixin class C3 = Object with M implements I {
905+
const C3();
906+
}
907+
888908
// Invalid mixin classes.
889-
mixin class E extends Object {} // Error.
890-
mixin class E with C {} // Error.
909+
mixin class E extends C {} // Error.
910+
mixin class E extends Object with M {} // Error.
911+
mixin class E with M {} // Error.
912+
mixin class E = C with M; // Error
913+
mixin class E = Object with M1, M2; // Error
891914
```
892915

893916
There are also changes to which declarations can be mixed in.
@@ -1130,6 +1153,10 @@ errors and fixups would help keep them on the rails.
11301153

11311154
## Changelog
11321155

1156+
1.8
1157+
1158+
* Allow any class declaration with `Object` as superclass to be a `mixin class`.
1159+
11331160
1.7
11341161

11351162
* Update the modifiers applied to anonymous mixin applications to closer

0 commit comments

Comments
 (0)