Skip to content

Possibly spurious error about mixin with constructor #59569

@lrhn

Description

@lrhn
mixin M {
  M.baz();
}
class MA with M {}
void main(){}

gives a warning of

main.dart:2:3: Error: Mixins can't declare constructors.
  M.baz();
  ^
main.dart:5:7: Error: Can't use 'M' as a mixin because it has constructors.
class MA with M {}
      ^
main.dart:2:3: Context: This constructor prevents using 'M' as a mixin.
  M.baz();
  ^

The error in line 5, "Can't use 'M' as a mixin because it has constructors.", feels misplaced.
The mixin M doesn't have constructors, because mixins can't have constructors. That's not preventing using it as a mixin, it's preventing the program from compiling.

The only real error, and the only one reported by the analyzer, is that mixin M can't declare a constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-front-endLegacy: Use area-dart-model instead.model-messagesPoor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions