dotnet / dotnet/fsharp

Tooltips for resolved generic parameters use wrong names, and introduce variables that aren't there

Open
#6,021 1 comment 1 reaction 0 assignees View on GitHub
Area-LangService-ToolTips Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

It comes in very handy that we can now see the generic parameters and whatever they've been resolved to, however, more often then not, they use the wrong generic-parameter naming:

![image](https://user-images.githubusercontent.com/16015770/50057196-42790f00-0167-11e9-970a-17cd7057c1eb.png)

### Repro steps

With a small repro, the names are still wrong, but a little bit "less wrong" than in the screenshot above. Paste the following code in Console project:

```f#

[]
module MapTest =
type Map<'U, 'V when 'U: comparison> with
/// A naive implementation of a Map.choose method:
static member choose chooser map =
map
|> Map.toArray
|> Array.choose (fun (key, value) -> match chooser key value with Some v -> Some(key, v) | _ -> None)
|> Map.ofArray

[]
let main _ =
let m = [1, "One"; 2, "Two"] |> Map.ofList
let m2 = m |> Map.choose (fun _ _ -> Some 'x')
```
And hover over the `Map.choose`, you'll see something like this:

![image](https://user-images.githubusercontent.com/16015770/50057549-2e83dc00-016c-11e9-88b3-c4790178fbb8.png)

### Expected behavior

The parameter names of the generic parameters in the function declaration should match the ones in the generic parameter instantiation list.

Also, it (probably) shouldn't list parameters that aren't there to begin with.

### Actual behavior

They don't match. Take the first screenshot above:

* `'Key` is not in the declaration at all, though it is resolved to `IComparable`
* `'Value` is not in the declaration at all, but here is resolved to `obj`, which suggests an error, but since all parameters are resolved, there is no error.
* `'a` is not in the declaration, but it matches to `'a2`
* `'b` is not in the declaration, but it matches to `'a3`
* `'c` is not in the declaration, but it matches to `'a4`
* the `...` in the "Generic parameters" suggests there are more items that aren't listed, but there were only three to begin with (5 are listed), so there shouldn't be any more.
* in the member declaration, `requires comparison and comparison and comparison` is not very helpful, and also incorrect: only `'a2` requires comparison here.

And if you take the second screenshot, there's still the 5 explained variables, whereas there are only 3 declared, and `'a` will match instead with `'a0` etc.

### Known workarounds

None, just use common sense to what is what, but like in the screenshot above, that isn't that easy sometimes.

### Related information

VS 2017, 15.9.3, F# 4.3.4 (I think, but looks like version doesn't matter here, I see it any project).

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.