Reputation: 1063
In the following code from Mixins in Dart, an application of mixin K
results in no warning, despite missing the superinterface method twice()
:
class S {
twice(int x) => 2 * x;
}
abstract class I {
twice(x);
}
abstract class J {
thrice(x);
}
class K extends S implements I, J {
int thrice(x) => 3* x;
}
class B {
twice(x) => x + x;
}
class A = B with K;
class D {
double(x) => x+x;
}
// E missing 'twice', thus not conforming to
// superinterface S of K. Yet no warning in
// checked mode under Dart 1.13.
class E = D with K;
main() {
/// A conforms to superinterface S of K
assert(new A().twice (1) == 2);
assert(new A().thrice(1) == 3);
/// E conforms to superinterface S of K
//assert(new E().twice (1) == 2); // NoSuchMethod 'twice'
assert(new E().thrice(1) == 3); // thrice() Provided by K
}
I'm mainly just wanting to fill in some holes in my understanding, so would appreciate someone pointing out any misuse of terms or bad concepts in my question here.
Upvotes: 2
Views: 235
Reputation: 71693
There were changes to how mixins work in Dart version 1.13. It's implemented in the VM, but not yet in dart2js, and I'm not sure about the analyzer.
Still, E
is a non-abstract class that doesn't implement its own interface (implements I
but doesn't have a non-abstract twice
member). That should cause a warning, mixins or no mixins.
On top of that, K
extends S
, so when using K
as a mixin, the mixin application's superclass should also implement S
which D
doesn't. That should give another warning.
Upvotes: 2