@@ -4,7 +4,7 @@ Author: Bob Nystrom, Lasse Nielsen
4
4
5
5
Status: Accepted
6
6
7
- Version 1.7
7
+ Version 1.8
8
8
9
9
Experiment flag: class-modifiers
10
10
@@ -556,7 +556,7 @@ The grammar is:
556
556
classDeclaration ::= (classModifiers | mixinClassModifiers) 'class' typeIdentifier
557
557
typeParameters? superclass? interfaces?
558
558
'{' (metadata classMemberDeclaration)* '}'
559
- | classModifiers 'class' mixinApplicationClass
559
+ | classModifiers 'mixin'? ' class' mixinApplicationClass
560
560
561
561
classModifiers ::= 'sealed'
562
562
| 'abstract'? ('base' | 'interface' | 'final')?
@@ -597,10 +597,11 @@ they are declared as subtypes of as follow.
597
597
598
598
* A declaration * S* is _ the declared superclass_ of a ` class ` declaration
599
599
* D* iff:
600
+
600
601
* * D* has an ` extends T ` clause and ` T ` denotes * S* .
601
602
* * D* has the form ` ... class ... = T with ... ` and ` T ` denotes * S* .
602
603
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
604
605
<code >* id* </code > or <code >* id* \< typeArgs\> </code >, and * id*
605
606
is an identifier or qualified identifier which resolves to * S* ,
606
607
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`.
835
836
It's a compile-time error if a `mixin class` declaration:
836
837
* has an `interface`, `final` or `sealed` modifier. _This is baked
837
838
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.
840
840
* declares any non-trivial generative constructor.
841
841
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
+
842
856
A *trivial generative constructor* is a generative constructor that:
843
857
* Is not a redirecting constructor _(`Foo(...) : this.other(...);`),
844
858
* declares no parameters (parameter list is precisely `()`),
@@ -885,9 +899,18 @@ mixin class C {
885
899
int? x;
886
900
}
887
901
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
+
888
908
// 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
891
914
```
892
915
893
916
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.
1130
1153
1131
1154
## Changelog
1132
1155
1156
+ 1.8
1157
+
1158
+ * Allow any class declaration with ` Object ` as superclass to be a ` mixin class ` .
1159
+
1133
1160
1.7
1134
1161
1135
1162
* Update the modifiers applied to anonymous mixin applications to closer
0 commit comments