This tracker is for issues related to:
- Analyzer
Env:
$ flutter --version
Flutter 1.12.13+hotfix.6 • channel unknown • unknown source
Framework • revision 18cd7a3601 (9 weeks ago) • 2019-12-11 06:35:39 -0800
Engine • revision 2994f7e1e6
Tools • Dart 2.7.0
I also confirmed the issue on Dartpad.
Shortest code for representation is below:
abstract class Y {
void hello();
}
mixin X on Y {
void callHello() => hello();
}
// error!
class YX with X implements Y {
@override
void hello() => print('hello YX');
}
void main() {
final yx = YX();
yx.callHello();
}
class YX with X implements Y
got an error say
‘X’ can’t be mixed onto ‘Object’ because ‘Object’ doesn’t implement ‘Y’.
Try extending the class ‘X’.dart(mixin_application_not_implemented_interface)
That message sounds pretty weird for me so I guess it might be a bug?
Looks like mixin restriction refers a superclass of “YX” so it claims “can’t be mixed onto ‘Object'”.
To convince analyzer I have to create a class which implement the interface then extends it like below:
class YI implements Y {
@override
void hello() => print('hello YI');
}
class YIX extends YI with X {}
My thoughts class YX with X implements Y
and class YIX extends YI with X
are fundamentally same as type level and also behavior.
This is working as intended.
class YX with X ..
meansclass YX extends Object with X ..
, and theon
clause specifies a constraint on the superclass thatX
is combined with in a ‘mixin application’ operation. AndObject
does indeed not implementY
.Maybe you did not intend to specify a requirement on the superclass that
X
can be mixin-applied to? The purpose of anon
clause in a mixin is basically to ensure that you can perform certainsuper
invocations, likesuper.hello()
. If you just want to ensure that the members ofY
are available such that they can be called onthis
in the body ofX
then you should usemixin X implements Y
.