-
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
Warn about expressions with no effect in void context #53537
Comments
In general, I think all functions with |
Hear, hear on the stronger However, it would mean that |
I would assume an assignment would have the same type as the right-hand expression, so that |
@lukehutch Exactly, so |
@lrhn ah, of course. Maybe assignments should be assumed to be of void type if their value is ignored, or if they are returned by a void lambda? It's probably safe to assume a user's intent when the user has initiated an action that has side effects. I am mostly concerned about the case where a lambda is created that was unintentionally written as a no-op. |
These are also valid statements with no effect: int;
5; Any statement that clearly has no effect should be flagged with a warning. |
Re-filing from dart-lang/language#3334 at the recommendation of @lrhn .
I have run into this issue numerous times, so I thought I would suggest a linter check to catch this...
(1):
(2):
The type of
onValueChanged
isvoid Function(String newValue)
, so there is no expected return value.Returning a non-void value from a void lambda, especially if it is only a reference (not the return value of a function call), should show a linter warning, since void functions should have side effects.
(Dart 3.1.0 / Linux)
The text was updated successfully, but these errors were encountered: