Skip to content

[feature-request] Improve mustCallSuper analysis #64062

Open

Description

@jellynoone

Dart version: Dart SDK version: 3.13.0 (stable) (Wed Aug 5 00:28:05 2026 -0700) on "macos_arm64"

Consider:

import 'package:meta/meta.dart';

void main() {
  Implementation().dispose();
}

class Base {
  @mustCallSuper
  void dispose() {
    print('disposed:base');
  }
}

mixin Mixin {
  @mustCallSuper
  void dispose() {
    print('disposed:mixin');
  }
}

class Implementation extends Base with Mixin {
  @override
  void dispose() {
    print('disposed:implementation');
    super.dispose();
  }
}

This prints:

disposed:implementation
disposed:mixin

Since Mixin overrides the base implementation, it's dispose isn't called. And because Mixin doesn't know about Base it can't call super.dispose().

However, because Base specifies mustCallSuper on dispose and since it isn't called in the disposal hierarchy I think there should be a warning on: class Implementation extends Base with Mixin {. Specifying Base's dispose isn't being called. Something, along the lines: 'Base.dispose()' is overridden and annotated as '@mustCallSuper', but it's never invoked.

However, if Mixin was defined as:

mixin Mixin on Base {
  @override
  @mustCallSuper
  void dispose() {
    print('disposed:mixin');
    super.dispose();
  }
}

There'd be no warning.

Related: #53549

Activity

  1. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    on Aug 17, 2026
  2. lrhn commented on Aug 18, 2026

    @lrhn
    Member

    The #53549 issue was solved by changing the Flutter mixin class, not by fixing the @mustCallSuper annotation behavior, so the problem probably still exists.

    My suggestion is to make it a warning if a mixin application has a concrete member overriding a concrete superclass member that is @mustCallSuper, and that member is not a @mustCallSuper member of any on-type of the mixin.
    (If the @mustCallSuper is on an on-type of the mixin, then it should already be a warning if the mixin member doesn't call super.member().)

    It's not perfect. If the member is a non-@mustCallSuper of an on type, the mixin member can contain a super.member() invocation. An alternative is to scan the mixin member body for a super-invocation when it overrides a @mustCallSuper member that exists in its on types, but not as @mustCallSuper. (If the member is not in the on types, then we know the mixin member cannot call super.member().)

    There are no plans to change how mixins work, this is only an issue with @mustCallSuper.

  3. added
    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).
    and removed
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    on Aug 21, 2026
  4. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    and removed
    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).
    on Aug 22, 2026
  5. added
    devexp-serverIssues related to some aspect of the analysis server
    type-enhancementA request for a change that isn't a bug
    and removed on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-serverIssues related to some aspect of the analysis servertype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions