New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mixins shadow super methods #12456
Comments
Nice. Of course, the restriction on mixins is an unfortunate expediency that will be relaxed at some point. In the meantime, this is a regrettable consequence. I think the correct thing to do is file a big against the restriction on mixins and then close this as working as intended. Added Accepted label. |
I encountered this while porting code to new DOM Custom Elements, I believe that getting an implicit initializer call will alleviate the need for the problematic initialization pattern. So yes, hopefully this won't cause any pain. |
This comment was originally written by @a14n What should be the output in the original example when init() is called on SubClass ? I expect the following : init sub! To get the following output : init sub! I think Mixin should be : class Mixin implements Superclass { // implements Unfortunatly using super in mixin is not allowed for now. I think this kind of mixin (with |
Alexandre, you are correct. I hope to relax these restrictions in time. They are only their for implementation reasons. |
Issue #16256 has been merged into this issue. |
The DEP to remove some of restrictions on mixins is available at https://github.com/gbracha/lessRestrictedMixins/blob/master/proposal.md |
No the answer is not as simple as allowing mixins to call super. There needs to be a way to access the individual super/mixin classes because you may not have access to edit those super/mixin classes to add the needed super call. One can't expect that ALL mixin methods in ALL libraries are going to have a super call either. There most likely won't be a super call in these methods. There will be cases where you can't edit the mixin method to add your needed super call. Then what?? Simply allowing super to be called is not a complete solution. |
Hopefully you guys can come up with a better elegant syntax than me but I'll throw out an idea to get people thinking.
then my made up example syntax could be:
This makes things simple. 1) You don't get caught up in unknown and unclear super call paths. 2) It gives you access to the required super classes you want. 3) Easy to read and understand what is going on. 4) And is always available to edit since you have access to edit your Subclass source code any way you wish. Think about it and get back to me please. |
I created #26194 to show more problems with super |
While it's not implemented everywhere yet, the language now supports super calls in mixins. |
Hmm, I guess it's still not done, so I'll consider this a duplicate of that main bug: #23770 |
Given the following class hierarchy:
class Superclass {
void init() {
print('init super!');
}
}
class Subclass extends Superclass with Mixin {
void init() {
print('init sub!');
super.init();
}
}
class Mixin {
void init() {
print('init mixin!');
}
}
Is it possible to call Superclass.init() when Subclass.init() is invoked? The Mixin class is prevented from calling super.init().
The text was updated successfully, but these errors were encountered: