-
Notifications
You must be signed in to change notification settings - Fork 1.7k
prefer_void_to_null false positive #57938
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
Another example is as follows:
|
Thanks for the feedback @gabrc! Mike put a bunch of thought into this one so I'll defer to @MichaelRFairhurst for thoughts... |
Any thoughts on this one @MichaelRFairhurst? |
Yeah, so these both actually stem from a kind of dubious usage of Null in my mind but I think others are free to disagree with me and therefore it probably should be allowed. But let me explain the issue with this pattern which most people don't consider. Firstly, it can be a totally invalid override to use
There are two potential issues here; one is that this may be a case of making the "billion dollar problem" worse. Is Of course, the intention may have been (in a future where we have nullable/non-nullable types):
even in this case there's a potential issue with defining The type So where your intention may be to mark it as Null so that it can't be used as a String, you are actually giving the missing name new behaviors:
This isn't a large risk, especially in a land of non-nullable types. But it poses some risk, especially today:
Imagine for instance that a user misunderstood
In this case, I think the best type is
and while currently
is probably best, I'd say that in a world of NNBD it is likely slightly safer to use
I'm not sure at what point we call these false positives or false negatives. Ultimately, the rule is doing its job by alerting you to places where you may be opening up your program to more fallout from the billion dollar mistake. However, it's certainly not valid to use void in these cases. I'm guessing that while the concerns I raise here probably make sense, you probably still view this as a useful pattern and we should probably suppress these errors. I also think that as long as there's some kind of dubiousness to the pattern then maybe its best to rely on |
The lint prefer_void_to_null reports issue with the following code:
The text was updated successfully, but these errors were encountered: