Fsharp: F12 / Go to definition does not go to the definition of a DU when types are combined with "and"

Created on 2 Sep 2017  路  3Comments  路  Source: dotnet/fsharp

Using F12 to go to the definition of discriminated unions does not work properly when the type is combined with and, it goes to one of the places where it is used in a declaration of a different DU.

This fails in VS2017 RTM and VS2017 latest Preview + Nightlies of F#. Verified to have worked correctly in VS2015.

Video:

f12gotodefinitionwrong

Repro steps

A minimal example is as follows:

module TestF12 =
    type Foo = MyFoo | YourFoo 

    and Bar = MyBar | YourBar 

    and FooBar =
        | Foo of Foo    // same behavior if it's OtherName of Foo
        | Bar of Bar

    let x = Foo MyFoo
    let y = Bar YourBar
    let tryFoo x: Foo option = if x = 1 then Some MyFoo  else None

Prerequisites:

  • The types must be combined with and
  • Case (i,.e. CaseName of SomeDU) and DU typename do not need to be the same
  • I have so far only observed this behavior with DU types

Expected behavior

F12, or the context menu, should go to the definition of the type, not one of its usages, even though the usage itself is declarative.

Actual behavior

It goes to the first usage in a different DU if the type-definition is combined with and. If there are multiple usages, it seems to jump to the first usage. If there are no usages, it jumps to the actual definition.

Note that the QuickInfo tooltip shows the correct info from the definition, it's only F12 / go to definition that fails here.

Known workarounds

Do not use and, however, that prohibits some use-cases.

Related information

Seen in:

  • VS2017 RTM
  • VS2017 latest Preview
  • VS2017 + F# nightlies

Not seen in:

  • VS2015

This makes this a regression bug, I believe.

Area-IDE Language Service Severity-Low bug

Most helpful comment

All 3 comments

Cool! Tx! Love it! :)

Closing this out as fixed in 15.8

works

Was this page helpful?
0 / 5 - 0 ratings