-
Notifications
You must be signed in to change notification settings - Fork 214
Make it an error to use a sealed class as a mixin #2651
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
Comments
We have the recurring issue of some people having declarations that they want to use as both a superclass and a mixin, with both I've wanted to get away from that for a long time, and have failed spectacularly to even move the needle, because making existing code invalid is a hard sell. (#1942, etc.) If we make a That suggests using language versioning to allow old code to still mix in a We could embrace the current use case instead, and allow you to declare a Alternatively we can allow you to write I think I prefer the |
I know we have a couple of existing classes that do this, but do you see users deliberately wanting to create new classes that are used both as mixins and classes? I can't recall any, and it's hard to see a compelling reason to support it. As I understand it, literally the only benefit you get from being able to use a mixin thing as a class too is that you can write That doesn't seem like enough value to me to justify supporting I'd rather just do #1942. In fact, #1942 might actually help users understand how mixins work because it starts to reinforce that a mixin is a superclass.
That's a fair point, but I can live with that. I think the set of people who maintain a class where:
Is likely to be very small and possibly empty. Whatever we do, I don't want to get stuck on this point such that we're unable to make progress on any other modifiers. I really want So I think it would be fine to do what this issue says and make it an error to mixin a class marked I could go either way. I just don't want to get stuck. |
I have a PR out (#2674) that addresses this by adding support for explicit |
Closing now that #2674 has merged. |
We eventually would like to move away from using classes as mixins. The base/interface/final proposal takes a step in that direction by preventing you from mixing in a class that has any of those modifiers. Since no classes have those modifiers today, we can do that since it's non-breaking.
We should do the same restriction for classes with the
sealed
modifier. If you want to mix in a sealed thing, that thing should be asealed mixin
, not asealed class
.The text was updated successfully, but these errors were encountered: