Dart Analyze logoDart Analyze/
DRT-W1707

Variable patterns in declaration context can't specify 'var' or 'final' keywordDRT-W1707

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a variable pattern is used within a declaration context.

Example

The following code produces this diagnostic because the variable patterns in the record pattern are in a declaration context:

void f((int, int) r) {
  var (var x, y) = r;
  print(x + y);
}

Common fixes

Remove the var or final keyword(s) within the variable pattern:

void f((int, int) r) {
  var (x, y) = r;
  print(x + y);
}