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.87k stars 781 forks source link

`open type T` when `T` is an enum is treated as unused even when it's used #17619

Closed brianrourkeboll closed 2 weeks ago

brianrourkeboll commented 2 weeks ago

Repro steps

// Shows as unused; the unused opens analyzer will suggest removing it.
open type System.DayOfWeek

// …Even though it's used.
let monday = Monday

Expected behavior

The open type declaration for an enum should be considered used if any of its enum cases are used unqualified.

Actual behavior

The open type declaration for an enum is considered unused even when one or more of its enum cases are used.

Known workarounds

N/A.

Related information

.NET 8, 9.

brianrourkeboll commented 2 weeks ago

I assume the fix involves yielding the enum cases as FSharpSymbols in here:

https://github.com/dotnet/fsharp/blob/6c96fc7065b178ca0a587d606e9eae3f1380a5b6/src/Compiler/Service/ServiceAnalysis.fs#L23-L54