dotnet / dotnet/fsharp

Unused opens false positive: extension method is preferred to instance method

Open
#5,306 4 comments 0 reactions 0 assignees View on GitHub
Area-LangService-UnusedOpens Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

During checking `open ...` statements, extension method is chosen instead of instance one, which differs from actual name resolution during the type check phase.
A guess before looking into: It may be another getting declaring vs apparent entity bug.

```csharp
using System;

namespace Ns1
{
public class Extended
{
public void M(Action a)
{
}
}
}

namespace Ns2
{
public static class Extension
{
public static void M(this Ns1.Extended b, Action a)
{
}
}
}
```

```fsharp
namespace ClassLibrary13

open Ns1
open Ns2

type T() =
member x.Foo(s: string) = ()

member x.Bar() =
Extended().M(x.Foo)
Extended().M(fun s -> x.Foo(s))
```
screen shot 2018-07-08 at 00 30 22
screen shot 2018-07-08 at 00 30 27

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.