G-Research / fsharp-analyzers

Analyzers for F#
https://g-research.github.io/fsharp-analyzers/
Apache License 2.0
14 stars 1 forks source link

Add disposedbeforeasyncrunanalyzer #57

Closed dawedawe closed 10 months ago

Smaug123 commented 10 months ago

We haven't got round to putting the analysers into the build pipeline for the service where this arose (I did one pass of fixing the analyser warnings, but I didn't merge the PR to add the analysers). I'm happy for us to get this into main and then enable the analysers on the pipeline and see in prod.

Smaug123 commented 10 months ago

It occurs to me that this (from my above comment) is a good test case for when the analyser should not trigger:

let asyncReturningFunc () =
    do
        use t1 = new blah
        use t2 = new blah
        ()
    async {
        ...
    }

(similarly if we have a let-binding rather than a do)

In this case, it's clear and explicit that the disposables are disposed before the async is returned, let alone before it's run.

dawedawe commented 10 months ago

It occurs to me that this (from my above comment) is a good test case for when the analyser should not trigger:

Thanks, I added the use inside a do as another negative test. The let was already covered in another negative test.