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 field not reported in Roslyn build #76729

Open
jjonescz opened this issue Jan 13, 2025 · 2 comments
Open

Unused field not reported in Roslyn build #76729

jjonescz opened this issue Jan 13, 2025 · 2 comments
Labels
Area-Analyzers Feature - IDE0052 Remove unread private members untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jjonescz
Copy link
Member

jjonescz commented Jan 13, 2025

Version Used: b7e891b

Not sure if this is infra or analyzer issue, but I would expect this unused field to generate IDE0052 warning during CI builds:

private static readonly char[] s_directorySeparator = [Path.DirectorySeparatorChar];

The IDE0052 warning is reported in IDE (both VS and VSCode) but not during builds.

Btw, this field reports the warning during builds if suppressions around it are removed:

private readonly SemanticModel _nullableEnabledSemanticModel;

@jjonescz jjonescz added Area-Analyzers Feature - IDE0052 Remove unread private members labels Jan 13, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 13, 2025
@davidwengier
Copy link
Member

davidwengier commented Feb 11, 2025

Saw this in Razor too with IDE0040, Remove accessibility modifiers.

We enabled the rule in our repo and fixed all violations in CI:
dotnet/razor#11466

But it seems our CI didn't pick up all the violations, as the SDK build failed due to violations in our code, after that change was inserted:
dotnet/sdk#46633 (comment)

The violations were shown in the IDE, but unless you know what files to look at, thats hardly very useful. It makes me very nervous to update anything in any of our .editorconfig files if we can't trust our own CI.

Some discussion and investigation, for context on Teams

@RikkiGibson
Copy link
Contributor

I want to say there are funky rules for whether a field is considered unused, when a non-constant is written to it. This came up when deciding on the rules for field keyword, when it is read but never written, or vice-versa. I believe the reasoning is that we don't want to advise the user to delete a field declaration, when its initializer may have side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Feature - IDE0052 Remove unread private members untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants