dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.58k forks source link

Possibly spurious error about mixin with constructor #59569

Open lrhn opened 1 day ago

lrhn commented 1 day ago
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.