Skip to main content

inference_failure_on_untyped_parameter

The type of {0} can't be inferred; a type must be explicitly provided.

Description

#

The analyzer produces this diagnostic when

  • the language option strict-inference has been enabled in the analysis options file,
  • the declaration of a formal parameter doesn't have a type, and
  • the type of the parameter can't be inferred.

The type of a parameter of a method can be inferred if the method overrides an inherited method.

Example

#

Given an analysis options file containing the following:

yaml
analyzer:
  language:
    strict-inference: true

The following code produces this diagnostic because the formal parameter p doesn't have an explicit type and the type can't be inferred:

dart
void f(p) => print(p);

Common fixes

#

Add an explicit type:

dart
void f(int p) => print(p);