-
Notifications
You must be signed in to change notification settings - Fork 2
Description
I was expecting that when removing the second restriction (that mixins can extend other classes), that the mixin application would include the code from both the mixin class declaration and its superclasses.
Let me use this code as an example:
class Base {
get f => 1;
}
class M1 {
get f => 2;
}
class M2 extends M1 {
get f => super.f;
}
class Test1 extends Base with M2 {
}Under the current proposal, what happens when evaluating new Test1().f?
If I understand things correctly, it seems that this would result in the value 1. That is because Sdynamic resolves to Base, not M1. Also, it seems that we'd produce a warning according to:
Let A be an application of MA. It is a static warning if the superclass of A is not a subtype of S.
because, even though Base is structurally like M1 it is not marked as a subtype of M1. Is that correct?
I was hoping that this code would not produce a warning, and would result in the value 2. In a way, equivalent to having the user write:
class Test2 extends Base with M1, M2 {
}The use case for this, is that we could have lots of classes that can be mixed in, and easily provide a mixin that users can apply to get a combination of those classes. For example:
class PolymerMini extends Object with AttributesFeature{ }
class PolymerAll extends PolymerMini with BindingFeature, TemplateFeature, RandomFeature {}
...
// A user simple mixes the combo of features he desires:
class MyElement extends HtmlElement with PolymerAll { ... }Backing up a bit: it seems to me that there are 2 possible meanings we could give to the extends M1 clause in a mixin.
- combine mixins: like in this example above.
- declare a context for
supercalls in mixins: what the current proposal does.
Not sure if we can have both with the same syntax. The current syntax makes me think more of the former, so maybe we could have a separate syntax for the latter?
Here are a couple a random and not that exciting ideas, where we would encode the current semantics that only the code in M2 is applied in the mixin, and we require the base class to implement M1:
// new keyword "within"
abstract class M2 within M1 {
get f => super.f;
}
// use an artificial "super" getter
abstract class M2 {
M1 get super; // declares that M2 should be applied in the context of an M1
get f => super.f;
}