linter icon indicating copy to clipboard operation
linter copied to clipboard

Warning about cancelling StreamSubscription given when subscription is nullable type.

Open safield opened this issue 3 years ago • 0 comments
trafficstars

Dart SDK version: 2.15.1 (stable) (Tue Dec 14 13:32:21 2021 +0100) on "linux_x64"

Observe the following class. The nullable subscription gives warning 'Cancel instances of StreamSubscription', where as the non nullable subscription gives no warning.

import 'dart:async';

class Test {
  StreamSubscription? _sub; // this line emits 'Cancel instances of StreamSubscription'
  late StreamSubscription _sub2;
  void cancel() {
    if(_sub != null) {
      _sub!.cancel();
    }
    _sub2.cancel();
  }
}

safield avatar Feb 04 '22 16:02 safield