dotnet / dotnet/fsharp

Tooltip shows wrong name resolution on uncallable static member due to name collision

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

Description

```fsharp
module Dom =

type WindowDelimiter =
| WindowDelimiter of int
static member FromCs (a: obj) = WindowDelimiter 1

type Tree =
| WindowDelimiter of WindowDelimiter
static member FromCs (a: obj) = WindowDelimiter(WindowDelimiter.WindowDelimiter(1))

let a = Dom.WindowDelimiter.FromCs null
```

**Expected behavior**

The last line should be OK, even the tooling shows the method in auto-complete, the signature is on the type tooltip, and the member definition highlights when the carret is on the invocation.

**Actual behavior**

> The field , constructor or member 'FromCs' is not defined

**Known workarounds**

@gusty pointed that SRTP trait call enables calling the member.

```fsharp
let inline fromCs< ^t when ^t : (static member FromCs : obj -> ^t)> (x:obj) =
(^t : (static member FromCs : obj -> 't) (x) )

let a = fromCs null
```

Another work around involve putting `RequireQualifiedAccess` which is not always possible / wanted.

**Related information**

Visual Studio 16.5.2

https://github.com/dotnet/fsharp/pull/6805#issuecomment-578721290 => a case where SRTP is useful to work around a compiler limitation.

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.