`use` binding for `IAsyncDisposable` not supported in F# interactive
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
`task` computation expressions do not support `use` or `use!` bindings for the `IAsyncDisposable` interface when used in F# interactive.
**Repro steps**
Make a type that implements `IAsyncDisposable` and bind it with a `use` or `use!` within a `task` CE:
```fsharp
open System
open System.Threading.Tasks
let asyncDisposable =
{ new IAsyncDisposable with
member _.DisposeAsync() =
printfn "Disposing async"
ValueTask() }
let t = task {
use d = asyncDisposable
return ()
}
```
**Expected behavior**
The code should compile.
**Actual behavior**
Error message in both the editor and F# interactive output window

```
>>
Script1.fsx(11,11): error FS0001: The type 'IAsyncDisposable' is not compatible with the type 'IDisposable'
```
**Known workarounds**
Use a `let` binding and call `DisposeAsync` explicitly, although this is not possible within a `finally` block.
**Related information**
Compiles and runs without issue in regular `.fs` files.
* Operating system: Windows 11, 22H2
* .NET Runtime kind: .NET 7.0.100, F# Interactive version 12.4.0.0 for F# 7.0
* Visual Studio Professional, 17.4.2
```powershell
>> dotnet --info
.NET SDK:
Version: 7.0.100
Commit: e12b7af219
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host:
Version: 7.0.0
Architecture: x64
Commit: d099f075e4
.NET SDKs installed:
7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```
Contributor guide
Assessment
This issue has not been assessed yet.