sdk icon indicating copy to clipboard operation
sdk copied to clipboard

unused_field improvement: detect self-assignment

Open stephane-archer opened this issue 1 year ago • 3 comments

class Counter extends ChangeNotifier {
  int _counter = 0;
  void increment() {
    _counter = 1;
  }

  void reset() {
    _counter = 0;
  }
}

The value of the field '_counter' isn't used. Try removing the field, or using it.

but

class Counter extends ChangeNotifier {
  int _counter = 0;
  void increment() {
    _counter = _counter + 1;
    //  _counter = _counter; is enough to make the warning disappear
  }

  void reset() {
    _counter = 0;
  }
}

now unused_field is happy but _counter is still an unused field in my opinion because it is used for a self-assignment

stephane-archer avatar Jul 10 '24 07:07 stephane-archer