dotnet / dotnet/fsharp

FSharpType.Format(displayContext) should take into account flexible types

Open
#17,915 3 comments 0 reactions 0 assignees View on GitHub
Area-Tooling Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

There is an API (`FSharpType.Format(displayContext)`) that provides a common way to present F# types to show in the editor.
But for flexible types (where generic parameters with the constraint are just compiler/runtime implementation details), `Format` returns the name of the generic parameter, which can be confusing, since the code explicitly specifies the type written as `#IDisposable ( & ... & ... )`, so the name of the generic parameter appears out of nowhere and at the moment does not reflect the expected type information (especially suitable for the editor) in any way.

**Repro steps**

Enable inlay type hints in editor

```F#
open System

let f (disposables: #IDisposable list) =
for x in disposables do ()
```

**Expected behavior**

For `x` provided expected type as `#IDisposable`

**Actual behavior**

Rider
![Image](https://github.com/user-attachments/assets/063b6816-a867-4b37-a996-5094978fdcf3)

VS Code
![Image](https://github.com/user-attachments/assets/e0479f5f-8c9c-47e3-9424-f44367fdea46)

Visual Studio
![Image](https://github.com/user-attachments/assets/ac6fc183-26d6-428a-ac7a-ce7826e8d925)

Example of FSharpType for `#IDisposable` ![Image](https://github.com/user-attachments/assets/457dcca6-9add-4434-b972-1618411f7264)

I would expect that this API fully formats the flexible type, providing ready information for the editor

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.