Workiva / dart_dev

Centralized tooling for Dart projects. Consistent interface across projects. Easily configurable.
https://pub.dartlang.org/packages/dart_dev
Apache License 2.0
74 stars 40 forks source link

Fix type mismatch between `DevTool.fromFunction()` and `DevTool.run()` #407

Closed evanweible-wf closed 1 year ago

evanweible-wf commented 1 year ago

Motivation

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);
}
aviary3-wk commented 1 year ago

Security Insights

No security relevant content was detected by automated scans.

Action Items

robbecker-wf commented 1 year ago

+10

robbecker-wf commented 1 year ago

@Workiva/release-management-p