Description
We currently allow some classes to be used as mixins. We always intended to stop doing that, but it's proven hard to make people migrate away from existing mixin-classes because someone might be extending the class as well, and you can't extends Mixin
with something declared by a mixin Mixin
declaration.
So, to move things along, we should:
- Allow a mixin declaration as a superclass, writing
class C extends Mixin ...
orclass C = Mixin with ...
. It effectively means usingObject with Mixin
as the superclass. (A desugaring would be that eachmixin Mixin ...
declaration gets a syntheticclass Mixin$class = Object with Mixin;
declaration next to it (fresh, unforgeable name), and all uses ofMixin
as superclass instead refers toMixin$class
). - Immediately deprecate writing
extends Mixin [ with ...]
and recommend it being written aswith Mixin [ , ...]
instead. Deprecateclass C = Mixin with ...
and recommendclass C = Object with Mixin, ...;
instead. - Deprecate using a class as a mixin (any mixin application of a class declaration), to encourage authors to migrate their mixin classes to
mixin
declarations.
This should allow changing all existing mixin-classes to mixin
declarations without breaking anyone, and it will encourage people to do so by giving deprecation warnings for any use of a class as a mixin, and any use of a mixin as a class.
The recommended approach is to use mixin
for anything which can be mixed in, and only use those with with
, not extends
.
In a later version of the language, we will then remove the ability to use mixins as superclasses again, along with the ability to use classes as mixins. That will likely not be before Dart 3.0.