-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Analyzer should warn if setter contains a return with a value #25228
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
Section 10.3 of the specification states:
and
So by omitting the return type you get a return type you can't explicitly state. That seems a bit strange. |
This |
totally agree with @zoechi here |
I quite like being able to use shorthand functions for setters, which are typically short. So ignoring an implicit return but flagging an explicit one might be reasonable. I'd be annoyed if it started flagging shorthand functions in setters. So I guess I agree with @zoechi too |
The analyzer now reports an error for the omitted void case:
|
Analyzer currently gives me a friendly warning in:
If I annotate that to any other type, it also correctly tells me I'm doing something wrong:
In fact, it won't even let me use
dynamic
:So it, really, clearly, obvious, undoubtedly, has a
void
return type. Even if I want to jam adynamic
in there to shut it up, it won't let me. Given that, if I omit the type:I should still get a warning on the return. The type of the body is void so the
return "bad";
is clearly wrong.Right now, the looser behavior when the type is omitted means you get better static analysis if you add the "void". That encourages people to adopt a pointlessly verbose style. Can we still be smart even if the "void" is omitted so I can tell people they don't have to add it?
The text was updated successfully, but these errors were encountered: