-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Method must be called #58175
Comments
void main() {
final A a = A();
// ...
}
class A extends Sink<int> {
@override
void add(int data) {
}
@override
void close() {
}
} |
Not exactly what I wanted to. |
Without global flow analysis a lint like this would be hard to enforce. (Note the various short-comings in See also: dart-archive/linter#2114 /fyi @bwilkerson |
I agree that it apparently leads to the slow global analysis. |
Unfortunately, that would also require a global analysis. The only performant checks we can make while you're typing are those that are local to the code being edited. That means that we can check, for example, that an object created in a method and not passed out of that method is also disposed in the same method. But as soon as a reference to the object escapes the method then we can't check to see whether it's disposed elsewhere so we can't know whether it's a problem if it isn't disposed in the same method. |
So, for my case I see two ways:
|
I don't understand your requirements, so I'm probably missing something, but it seems like the two options are orthogonal. If the goal is to disallow code from calling If your goal is to be able to detect at analysis time the error of not closing the sink, then I don't know of any solution for that. The best approach I'm aware of is to follow some convention(s) that make it very hard to forget to close it (such as always closing it in the same method in which it is created). |
My goal is to have a |
Describe the rule you'd like to see implemented
Add an annotation for method that must be called at least once from somewhere and linter warning if it's not the case.
Examples


If I do not close a StreamSink, linter warns:
If I close it in dispose() but do not call _bloc.dispose() from my StatefulWidget's dispose(), linter doesn't notice it.
Thus we easily can have memory leaks and never know about it. That's why I propose such a rule.
The text was updated successfully, but these errors were encountered: