Skip to content

Allow mixins in "extends" clauses #1942

Closed as not planned
Closed as not planned
@munificent

Description

@munificent

We would like to deprecate and eventually stop supporting using class declarations as mixins. There are a couple of proposals out for how to do that: #1529 and #1643. The main sticking point for simply making it a warning or error to mix in a class is Flutter.

Flutter has a number of class declarations that are widely used as both mixins (in with clauses) and as superclasses (in extends clauses). Flutter can't change those class declarations to be explicit mixin declarations because it would break every extends use of the classes in the wild today.

We could potentially have a deprecation period where we encourage Flutter users to change all of those extends ___ to extends Object with ___, but it's not clear that that's actually a desirable ecosystem change. Most Dart users seem to be unaware of mixins so forcing them to learn about with before they can use common functionality like ChangeNotifier might be punishing for little benefit.

Here is a simpler proposal:

  1. Allow using extends ___ on mixins and treat it as syntactic sugar for extends Object with ___. Unlike the previous proposals, we don't make this a temporary language feature. Instead, we simply allow that sugar henceforth and forever.

    With this, Flutter classes like ChangeNotifier can immediately be changed to mixin instead of class without breaking or effecting any users.

  2. After Flutter and other key packages have migrated their mixin-in-able classes to use mixin, add a linter rule that warns when users mixin a type declared using class. Eventually promote that to a warning.

  3. In Dart 3.0, remove support for mixing in classes. Continue to allow mixins to appear in extends clauses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemssmall-featureA small feature which is relatively cheap to implement.smaller-dart

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions