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

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

Open
joprice opened this issue Oct 26, 2024 · 1 comment
Open

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

joprice opened this issue Oct 26, 2024 · 1 comment

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.

@github-actions github-actions bot added this to the Backlog milestone Oct 26, 2024
@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

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

No branches or pull requests

2 participants