DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1605

Incompatible return type for closureDRT-W1605

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when the static type of a returned expression isn't assignable to the return type that the closure is required to have.

Example

The following code produces this diagnostic because f is defined to be a function that returns a String, but the closure assigned to it returns an int:

String Function(String) f = (s) => 3;

Common fixes

If the return type is correct, then replace the returned value with a value of the correct type, possibly by converting the existing value:

String Function(String) f = (s) => 3.toString();