Open
Description
Consider the following definition of Completer.complete()
:
abstract class Completer<T> {
void complete([FutureOr<T>? value]);
}
Now look at the following code:
void main() {
Completer<int> completer = Completer<int>();
completer.future.then((int value) {
print(value);
});
completer.complete(null);
}
When running in sound null-safety, that code will produce no static analysis errors, compile cleanly, and throw a runtime error when it hits the call to completer.complete(null)
. This is highly counterintuitive and confusing to developers (at least it was to me when I ran into it).
Upon inspection, it's clear that this is clean to analysis because the completion value argument is optional. While this signature made sense in a pre-null-safety world, it's just going to be a source of errors when running with null safety.
I think we should consider a language change to fix this.
Metadata
Metadata
Assignees
Labels
No labels