G-Research / fsharp-analyzers

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

Expansion of dispose-before-async-is-run #75

Closed Smaug123 closed 4 months ago

Smaug123 commented 4 months ago

I've just raised https://github.com/G-Research/fsharp-analyzers/pull/74 which contains a failing test case reproducing a situation I encountered at work which the analysers currently do not catch:

module Program =
    let doIt () =
        let blah, anInt = DisposableThing.make ()
        use blah = blah
        match anInt with
        | 3 -> failwith "it wasn't 5"
        | _ ->
            async {
                return "hi"
            }

I guess this might be harder to analyse, and it's not immediately clear to me what the correct algorithm is here (maybe "use statement appears anywhere at top level of function, not in an async block" is actually the right heuristic?)