inference_ failure_ on_ collection_ literal
The type argument(s) of '{0}' can't be inferred.
Description
#The analyzer produces this diagnostic when
- the language option
strict-inference
has been enabled in the analysis options file, - a list, map or set literal doesn't have type arguments, and
- the values for the type arguments can't be inferred from the elements.
Example
#Given an analysis options file containing the following:
analyzer:
language:
strict-inference: true
The following code produces this diagnostic because the type of the elements of the list literal can't be inferred by the analyzer:
void f() {
var list = [];
print(list);
}
Common fixes
#Provide explicit type arguments for the literal:
void f() {
var list = <int>[];
print(list);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.