-
Notifications
You must be signed in to change notification settings - Fork 30
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
Consider cast_nullable_to_non_nullable
for core lints
#28
Comments
For reference, the lint is enabled in the flutter framework code base and has successfully caught some issues there, I believe. |
Should update GOOD to also include this 2nd case: class A {}
class B extends A {}
A? a;
var v = a as B?; cc @pq |
Would like to undetstand how this affects Google3 before making a choice. |
@mit-mit Do you know somebody who could drive trying this out in g3? |
@pq are you looking at that? |
I can take a look. 👍 |
I did a run and sent results out to a handful of folks for further review. At first blush the results seem valuable to me. If you want access (and are a Googler, sorry), let me know! |
See: dart-lang/lints#28 Change-Id: Ic0dac81467a3a3fbe7f7bf805ee59e3844edb6a1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303681 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
cast_nullable_to_non_nullable
for core lints
I'm not strongly convinced that this lint is a win. I deliberately write If I cast from If I cast from So, should this be more about unrelated casts or down-casts? (All in all, not getting my vote for adding to core lints.) |
But it may also be that that you meant to cast
Why? Clearly indicating that you know that you are both removing nullability and changing the base type doesn't seem ridiculous to me, since as a reader I can be confident that both casts are intentional, vs the case above where I can't. |
I'm generally concerned about That said, if I'd still be against including it in the core lints. To get there, I'd want it to either:
Yes, you can make mistakes with Which raises the question, if |
Yes, that's why my preferred solution would be dart-lang/language#1547. That didn't go anywhere though, and if we're going to be stuck with having to use an operator that can do anything, even the things I did not intend to do, a default lint was the next best option. |
See discussion in dart-lang/language#1547. Casting
Foo?
toBar
(vsBar?
) withas
is an easy mistake to miss.The text was updated successfully, but these errors were encountered: