-
Notifications
You must be signed in to change notification settings - Fork 1.7k
new annotation to identify classes safe for use as mixins #47437
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
Spitballing names:
|
I think it's worth considering some of the alternatives to creating an annotation before we do so, but if we do create an annotation I suspect that finding a good name will be a challenge. The one listed above seems a bit repetitive:
We could shorten it
but that seems potentially confusing because there are differences between a class that's used as a mixin and an actual mixin. I'm not coming up with a suggestion I really like at the moment, though I did think of a minor riff on a another suggestion you made:
Still not great. |
See also dart-lang/language#1529 and dart-lang/language#1643. Assuming we're allowing a class to be used as both a class and a mixin, I'm inclined towards |
We're currently allowing it, and it would be nice to mark those classes that should really be mixins as exceptions to a rule of not using classes as mixins. (And recommending you change How about just using const mixin = pragma("analyzer:mixin_class");
@mixin
class JumpingJehoshaphat {
void jump() {
print("How high?");
}
} The word Also, it reads as "I really mean this to be a mixin". (I'd use a |
I believe we've arrived at a near consensus that /fyi @jcollins-g |
Not sure what the difference between an annotation and a pragma is, pragmas are annotations. I'm perfectly fine with annotating platform mixin-classes with That would require the analyzer to recognize both that pragma and whichever Also, we are currently considering allowing you to write |
Accidentally submitted comment instead of canceling it. Sorry for the confusion. |
@lrhn I don't quite follow this. I may have missed some of the conversation in another venue, but why do you not want this to show up anywhere (by which I presume you mean something like API docs)? This seems relevant to users to know (that this class is expected to continue to be valid to use as a mixin, unlike other classes). |
I don't want it to show up in documentation, because then I also have to document that annotation in the platform libraries, otherwise they won't be stand-alone readable. The classes are named The annotation is for tools. It's there to avoid the analyzer giving a warning if someone does mix the classes in. The success criteria is not getting a warning, and a hidden annotation does that perfectly (so would a hard-coded list, which is what we have today, and I'd also be happy to keep that. Whichever is easier, as long as we don't start getting warnings.) It's also a short-term thing, I hope to make all the classes into |
Personally, I'd rather leave the hard coded list in analyzer for now because it will be easier to remove the hardcoded exceptions than it will be to remove code that handles |
This is an interesting point. Looking ahead, do we want to consider supporting pragma advice for the analyzer? If not, this would be wasted effort for sure. (Note I have a parallel question for the Flutter SDK, about which the analyzer platform is intimately aware -- not in a good way!)
This would indeed be really unfortunate. My thinking is that regardless of what we do for the SDK (if anything) we might still want something in
Given this, the point may be moot for this specific use case and maybe adding |
I have no objection to adding support for some forms of And if
I doubt that the Flutter SDK is going to want to use I agree that we want to decouple the analyzer from the Flutter SDK, but I think we can do so by introducing new annotations that have the desired meaning. However, if we need to support some form of
Absolutely. I wasn't suggesting that we not add an annotation to
Agreed. I didn't intend to say that we should never support We could also prevent that from happening by supporting |
Thanks Brian!
I hope this is true. My biggest concern is how this would scale. I wouldn't want (Anyway, this is a bigger conversation for another thread!)
Ideally we wouldn't but this depends on whether we want to allow the SDK APIs to advise analysis themselves and if we do, if it's reasonable for the SDK to use the same mechanism for specifying these semantics as external users (e.g., annotations shared w/ |
I think you already know that I agree :-), but it's worth mentioning anyway. We should always work toward more widely applicable solutions.
In general, I think we do want that.
I think it's clear that the SDK can't use annotations defined in
In general, I'd prefer we didn't do that. If it weren't for the fact that
I'd be in favor of supporting a more general solution in this case too. |
😄
💯 For this case in particular I think you're right that the solution would be short-lived. That said, if this case motivated a solution that would get us pointed in a desired direction then maybe that's moot. I take it the rub is getting agreement on to what extent we want to aspire to SDK APIs that advise analysis themselves and that's I think a bigger question for the language and analyzer teams to hash out. Related to this is the Flutter use-case that motivated this conversation in the first place. What's interesting there is that Flutter has an aspiration to support forks (which I think suggests that our tools should too). Our current Flutter-awareness is too brittle to do that reliably or at all (since it depends fundamentally on hardwired classnames and URIs). Portable Flutter analysis is a different requirement than the aspiration to improve analyzer hygiene and maintainability but it's interesting to note the overlaps. Thanks all for the thoughtful responses! |
With the addition of the As for the pragma/ |
More context in #58543.
TL;DR: some classes are intended to be mixed in and it would be great if an annotation could teach the
prefer_mixin
lint about them.The text was updated successfully, but these errors were encountered: