Linter: Close instances of dart.core.sink doesn't recognize close when using this

Created on 23 Feb 2019  ·  7Comments  ·  Source: dart-lang/linter

Describe the issue
When closing the Sink with accessing to it through this warning appears that the Sink is not closed even tho it is.

To Reproduce

  1. Add a property of type Sink in your class
  2. Close the sink using this.sink.close()
  3. Warning Close instances of dart.core.Sink appears
  4. Remove this
  5. No more warnings

Expected behavior
There should be no warnings when closing the dart.core.Sink with or without accessing to it through this.

Is this working as expected? To me it looks it's not.

bug false positive

Most helpful comment

Sorry @grandpa-guru. Not yet. I'll try and take a look this week. 🤞

All 7 comments

Thanks for the report @grandpa-guru! It looks like this is easy to reproduce:

class B0 {
  IOSink _sinkB0; // <= Wrongly flagged.
  void init(filename) {
    _sinkB0 = new File(filename).openWrite();
  }

  void dispose(filename) {
    // ignore: unnecessary_this
    this._sinkB0.close();
  }
}

We'll take a look at a fix. 👍

Thanks for the report @grandpa-guru! It looks like this is easy to reproduce:

class B0 {
  IOSink _sinkB0; // <= Wrongly flagged.
  void init(filename) {
    _sinkB0 = new File(filename).openWrite();
  }

  void dispose(filename) {
    // ignore: unnecessary_this
    this._sinkB0.close();
  }
}

We'll take a look at a fix. 👍

Any progress on this?

Sorry @grandpa-guru. Not yet. I'll try and take a look this week. 🤞

This is still happening to me:
```dart
class PLCVarControlScreen extends StatefulWidget {
@override
_PLCVarControlScreenState createState() => _PLCVarControlScreenState();
}

class _PLCVarControlScreenState extends State {
// This gives warning: Close instances of dart.core.Sink.
StreamController _plcStreamController;

@override
void dispose() {
super.dispose();
this._plcStreamController.close();
}
...
}
```

Any progress? :)

Sorry, no significant progress. I took a look tonight but it's a bit hairy and I need to get back a little more context.

Sorry for the delay!

@pq , Hey, any news? 🗞️

Hey @LukaGiorgadze. Sorry... no. This keeps falling off. I'll try and bump it back up.

Thanks for your patience!

Was this page helpful?
0 / 5 - 0 ratings