linter
linter copied to clipboard
Warning about cancelling StreamSubscription given when subscription is nullable type.
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();
}
}