dotnet / dotnet/fsharp

Module import is considered unused if it used only for an extension method used in a CE

Open
#11,626 4 comments 1 reaction 0 assignees View on GitHub
Area-FCS Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Repro steps**
Consider the following code:

```fsharp
open System.Threading.Tasks

module Builder =

type AsyncBuilder with
// allows to bind to the result of Tasks
member _.Bind (task : Task<'a>, cont : 'a -> Async<'b>) =
async.Bind (Async.AwaitTask task, cont)

open Builder

let task = Task.FromResult 1
let x = async {
let! i = task
return i + 1
}
```

Here the `Builder` module contains an extension method for an `AsyncBuilder` that enables the former to bind to the results of usual .Net tasks.

**Expected behavior**

No compiler warnings or errors.

**Actual behavior**

F# compiler considers this import to be not required:
Warning "IDE0005: Open declaration can be removed".

![image](https://user-images.githubusercontent.com/3943804/120668601-e74e4a80-c48e-11eb-8265-1250aeca7c6b.png)

But it is required as without it the compiler generates an error:
```
X.fs(16, 14): [FS0001] This expression was expected to have type
'Async<'a>'
but here has type
'Task'
```

**Related information**

* Operating system — Windows 10
* .NET Framework 4.7.2
* Visual Studio 16.10.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.