Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brianrourkeboll opened this issue Aug 27, 2024 · 1 comment · Fixed by #17628
Closed

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

brianrourkeboll opened this issue Aug 27, 2024 · 1 comment · Fixed by #17628

Comments

@brianrourkeboll
Copy link
Contributor

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
Copy link
Contributor Author

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

/// Compute an indexed table of the set of symbols revealed by 'open', on-demand
let revealedSymbols: Lazy<HashSet<FSharpSymbol>> =
lazy
let symbols: FSharpSymbol[] =
[|
for ent in entity.NestedEntities do
ent
if ent.IsFSharpRecord then
for rf in ent.FSharpFields do
rf
if ent.IsFSharpUnion && not (ent.HasAttribute<RequireQualifiedAccessAttribute>()) then
for unionCase in ent.UnionCases do
unionCase
if ent.HasAttribute<ExtensionAttribute>() then
for fv in ent.MembersFunctionsAndValues do
// fv.IsExtensionMember is always false for C# extension methods returning by `MembersFunctionsAndValues`,
// so we have to check Extension attribute instead.
// (note: fv.IsExtensionMember has proper value for symbols returning by GetAllUsesOfAllSymbolsInFile though)
if fv.HasAttribute<ExtensionAttribute>() then
fv
for apCase in entity.ActivePatternCases do
apCase
// The IsNamespace and IsFSharpModule cases are handled by looking at DeclaringEntity below
if not entity.IsNamespace && not entity.IsFSharpModule then
for fv in entity.MembersFunctionsAndValues do
fv
|]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant