inference_ failure_ on_ function_ return_ type
The return type of '{0}' can't be inferred.
Description
#The analyzer produces this diagnostic when:
- the language option
strict-inferenceis enabled in the analysis options file, - the declaration of a method or function has no return type, and
- the return type can't be inferred.
Example
#Given an analysis options file containing the following:
analyzer:
language:
strict-inference: true
The following code produces this diagnostic because the method m doesn't
have a return type:
class C {
m() => 7;
}
Common fixes
#Add a return type to the method or function:
class C {
int m() => 7;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Page last updated on 2025-9-16. View source or report an issue.