Skip to main content

pattern_type_mismatch_in_irrefutable_context

The matched value of type '{0}' isn't assignable to the required type '{1}'.

Description

#

The analyzer produces this diagnostic when the type of the value on the right-hand side of a pattern assignment or pattern declaration doesn't match the type required by the pattern being used to match it.

Example

#

The following code produces this diagnostic because x might not be a String and hence might not match the object pattern:

dart
void f(Object x) {
  var String(length: a) = x;
  print(a);
}

Common fixes

#

Change the code so that the type of the expression on the right-hand side matches the type required by the pattern:

dart
void f(String x) {
  var String(length: a) = x;
  print(a);
}