Skip to content

unused open when AutoOpen used on type with static members #17929

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

Closed
joprice opened this issue Oct 26, 2024 · 2 comments · May be fixed by #18510
Closed

unused open when AutoOpen used on type with static members #17929

joprice opened this issue Oct 26, 2024 · 2 comments · May be fixed by #18510

Comments

@joprice
Copy link

joprice commented Oct 26, 2024

When opening a namespace that contains a type annotated with [<AutoOpen>], the open is identified as being unused even when the static members of the type are referenced.

Here is a test that triggers the diagnostic: main...joprice:fsharp:autoOpenType

From a quick inspection of the code, I would guess this has to do with this guard, which only checks for declarations in namespaces and modules, but not static type members:

| Some entity when entity.IsNamespace || entity.IsFSharpModule ->

Expected behavior

Unused open analysis should behave with respect to [<AutoOpen>] for types as it does for modules.

Actual behavior

The open is marked as unused, even though removing it causes the file to fail to compile.

Known workarounds

Fully qualify the member access.

@edgarfgp
Copy link
Contributor

Extracted from the repro link.

namespace SomeOtherNamespace

[<AutoOpen>]
type SomeUnusedType =
    static member y = 1

namespace Test

open SomeOtherNamespace

type UseTheThings(i:int) =
    member x.UseSomeOtherNamespaceTypeMember() = y

@psfinaki
Copy link
Member

Looks like a dupe of this one.

@psfinaki psfinaki closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2024
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.

3 participants