Skip to main content

unnecessary_statements

Unnecessary statement.

Description

#

The analyzer produces this diagnostic when an expression statement has no clear effect.

Example

#

The following code produces this diagnostic because the addition of the returned values from the two invocations has no clear effect:

dart
void f(int Function() first, int Function() second) {
  first() + second();
}

Common fixes

#

If the expression doesn't need to be computed, then remove it:

dart
void f(int Function() first, int Function() second) {
}

If the value of the expression is needed, then make use of it, possibly assigning it to a local variable first:

dart
void f(int Function() first, int Function() second) {
  print(first() + second());
}

If portions of the expression need to be executed, then remove the unnecessary portions:

dart
void f(int Function() first, int Function() second) {
  first();
  second();
}