fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Allow `_` in async `use! _` pattern (lift FS1228 restriction)

Open bent-rasmussen opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

I am a bit surprised that use _ (discard) is valid, like in this code:

// okay
use _ = { new IDisposable with member _.Dispose() = printfn "disposed" }
// ...

...whereas use! _ is invalid, like in this code:

// error FS1228: 'use!' bindings must be of the form 'use! <var> = <expr>'
async {
    use! _ = Async.OnCancel (fun () -> printfn "disposed")
    // ...
}

I am also not getting good results when googling FS1288.

Describe the solution you'd like

I expect to be able to use the discard "pattern" (?) in both cases.

Perhaps this is more complicated to implement than it looks like at first glance.

Describe alternatives you've considered

I am currently using __ (double _), which is exactly what I used before use _ became valid code.

Additional context

None.

bent-rasmussen avatar Nov 26 '23 22:11 bent-rasmussen