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 ... or class C = Mixin with .... It effectively means using Object with Mixin as the superclass. (A desugaring would be that each mixin Mixin ... declaration gets a synthetic class Mixin$class = Object with Mixin; declaration next to it (fresh, unforgeable name), and all uses of Mixin as superclass instead refers to Mixin$class).
- Immediately deprecate writing
extends Mixin [ with ...] and recommend it being written as with Mixin [ , ...] instead. Deprecate class C = Mixin with ... and recommend class 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.
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 Mixinwith something declared by amixin Mixindeclaration.So, to move things along, we should:
class C extends Mixin ...orclass C = Mixin with .... It effectively means usingObject with Mixinas 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 ofMixinas superclass instead refers toMixin$class).extends Mixin [ with ...]and recommend it being written aswith Mixin [ , ...]instead. Deprecateclass C = Mixin with ...and recommendclass C = Object with Mixin, ...;instead.mixindeclarations.This should allow changing all existing mixin-classes to
mixindeclarations 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
mixinfor anything which can be mixed in, and only use those withwith, notextends.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.