dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.86k stars 779 forks source link

Tooltip in IDE suggests wrong type of parameter or even multiple types #17036

Open BoundedChenn31 opened 4 months ago

BoundedChenn31 commented 4 months ago

Repro steps

type U1 = { Name: string }
type U2 = { Age: int; Name: string }

let test =
    seq<U1 -> string> {
        fun u -> u.Name
    }
    |> Seq.map (fun (f: U1 -> string) -> [| f |])
  1. Hover over u parameter. Tooltip says that it's type is U2 but it is U1 actually.

2024-04-11_203434

  1. Also, for .Name-part tooltip shows both types U1 and U2. I would expect to see only one type.

2024-04-11_203445

As far as I can see code compiles and runs correctly without runtime errors, IL doesn't mention U2 type besides declaration.

I suspect these problems are related but tell me if I should create separate issue for each one :)

Related information

brianrourkeboll commented 4 months ago

The same thing also shows with Ionide in VS Code:

https://github.com/dotnet/fsharp/assets/14795984/ecb072fd-ad85-49a8-9bd9-cd54e6810ca8

BoundedChenn31 commented 4 months ago

Noticed that the same code fails to compile with 7.0.202 SDK. Compiler treats u as U2 and doesn't see seq<U1 -> string> when deducing:

Error FS0193 : Type constraint mismatch. The type 
    'U2 -> string'    
is not compatible with type
    'U1 -> string'

Really hope that it's not a regression, I don't want to write fun (u: U1) -> u.Name again in the future :laughing: