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

StructDiscriminatedUnionAnalyzer vs. StructuredFormatDisplayAttribute #102

Open
Numpsy opened this issue Jun 30, 2024 · 2 comments
Open

Comments

@Numpsy
Copy link
Contributor

Numpsy commented Jun 30, 2024

Describe the bug
I was just running a new project through the analyzers, and had thought that I might get a StructDiscriminatedUnionAnalyzer suggestion from a DU that only has empty and string members, but I got nothing.

Looking at my code, the DU in question has a StructuredFormatDisplay attribute, and removing that causes a Consider adding [<Struct>] to Discriminated Union suggestion to appear.

I'm not sure if that is intentional or not, but looking at the analyzer code I wonder if the StartsWith("Struct" at

| Some structIdent -> structIdent.idText.StartsWith("Struct", StringComparison.Ordinal)
is perhaps matching more things than it should?

To Reproduce

Running the analyzer against a DU such as

type LicenseValidationResult =
    | Valid
    | Invalid of error: string

results in a Hint IONIDE-012 : Consider adding [<Struct>] to Discriminated Union suggestion, but running it against

[<StructuredFormatDisplay("{DisplayText}")>]
type LicenseValidationResult =
    | Valid
    | Invalid of error: string

has no hint.

Environment (please complete the following information):
Ionide analyzers version 0.11.0

@nojaf
Copy link
Contributor

nojaf commented Jul 1, 2024

Thanks for reporting this. Yes, our check could be better I see.
Would you be interested in submitting a PR for this?

@Numpsy
Copy link
Contributor Author

Numpsy commented Jul 1, 2024

I'll have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants