-
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
[Analyzer] null-safe no warning or compilation error for Completer.complete() #45319
Comments
According to the
So it is statically valid to complete a This is also true for @lrhn @bwilkerson I think it makes sense for the analyzer to Hint here, given the guarantee to throw at runtime. WDYT? Something like:
Examples: void m1() => Completer<int>().complete(); // proposed Hint
void m2() => Completer<int>().complete(null); // proposed Hint
void m3(Null a) => Completer<int>().complete(a); // proposed Hint
void m4(FutureOr<Null> a) => Completer<int>().complete(a); // existing Error
void m5(Future<Null>? a) => Completer<int>().complete(a); // existing Error
void m6(void a) => Completer<int>().complete(a); // existing Error
void m7(Future<void> a) => Completer<int>().complete(a); // existing Error
void m8(FutureOr<void> a) => Completer<int>().complete(a); // existing Error
void m9(Never a) => Completer<int>().complete(a); // proposed Hint
void m10(Future<Never> a) => Completer<int>().complete(a); // proposed Hint
void m11(FutureOr<Never> a) => Completer<int>().complete(a); // proposed Hint |
I agree. Any time there is guaranteed to be a runtime exception and we can accurately determine that case statically then it makes sense for analyzer to produce a hint.
I'm not sure about |
If the argument has type For The cases that really needs help is "no argument, non-nullable type" and possibly "nullable argument, non-nullable type", where the latter is enabled because the value is optional and therefore forced to be nullable. The latter call might actually be correct if you know, for some reason not reflected in the type system, that the value is not null. Wouldn't hurt you to write the |
Excellent, thanks for the feedback! |
I've opened https://dart-review.googlesource.com/c/sdk/+/202622. It handles "no argument, non-nullable type" and "null argument, non-nullable type" since those can't have false positives. I can change it to handle "nullable argument, non-nullable type" too but I'm not sure if it should be a default diagnostic if it can have false positives? In particular, it would warn about |
@simolus3 I think your decision is sound. Later on, we can trigger on nullable arguments either in the same Hint, or with a new Hint (with a different message). |
This tracker is for issues related to:
Analyzer
Dart SDK Version (
dart --version
)Dart SDK version: 2.12.0 (stable) (Thu Feb 25 19:50:53 2021 +0100) on "macos_x64"
Dart analyzer don't provide warning or compilation error when Map<String, Completer> is passed to a function with argument Map<String, Completer<Object?>>. But throws a error at runtime which basically remove all the benefits of a null/type safe code.
As you can see Completer is not equal to Completer<Object?>
code to replicate:
The text was updated successfully, but these errors were encountered: