The DevTool interface defines a run() method that must return FutureOr<int?>. The DevTool.fromFunction() factory expects a function with a return type of FutureOr<int>?. As a result, functions that would be valid implementations of DevTool.run() are disallowed by the typing of DevTool.fromFunction().
Changes
Update the typing of DevTool.fromFunction() to match that of DevTool.run(). The updated type is more permissive and should not be breaking. To illustrate:
FutureOr<int?> fnTest1(DevToolExecutionContext context) {}
FutureOr<int?> fnTest2(DevToolExecutionContext context) async {}
FutureOr<int>? fnTest3(DevToolExecutionContext context) {}
FutureOr<int>? fnTest4(DevToolExecutionContext context) async => 0;
void tests() {
DevTool.fromFunction(fnTest1); // Previously a type error, now works.
DevTool.fromFunction(fnTest2); // Previously a type error, now works.
DevTool.fromFunction(fnTest3);
DevTool.fromFunction(fnTest4);
}
Motivation
The
DevTool
interface defines arun()
method that must returnFutureOr<int?>
. TheDevTool.fromFunction()
factory expects a function with a return type ofFutureOr<int>?
. As a result, functions that would be valid implementations ofDevTool.run()
are disallowed by the typing ofDevTool.fromFunction()
.Changes
Update the typing of
DevTool.fromFunction()
to match that ofDevTool.run()
. The updated type is more permissive and should not be breaking. To illustrate: