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

CA1822 Mark members as static removes iterator modifier VB #7433

Open
CoolCoderSuper opened this issue Oct 4, 2024 · 1 comment
Open

CA1822 Mark members as static removes iterator modifier VB #7433

CoolCoderSuper opened this issue Oct 4, 2024 · 1 comment

Comments

@CoolCoderSuper
Copy link

Analyzer

Diagnostic ID: CA1822: Mark members as static

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.100

Describe the bug

Applying make static analyzer in VB removes the Iterator modifier.

Expected behavior

The Shared modifier is added to the method and keeps existing modifiers.

Actual behavior

Shared modifier replaces Iterator modifier.

Additional context

Screen.Recording.2024-10-04.103537.mp4
@CoolCoderSuper CoolCoderSuper changed the title Mark members as static removes iterator modifier VB CA1822 Mark members as static removes iterator modifier VB Oct 4, 2024
@CoolCoderSuper
Copy link
Author

CoolCoderSuper commented Oct 4, 2024

The reason for this is that SyntaxtGenerator being language agnostic

// Update definition to add static modifier.
document = solution.GetDocument(document.Id)!;
root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
node = root.GetAnnotatedNodes(s_annotationForFixedDeclaration).Single();
var syntaxGenerator = SyntaxGenerator.GetGenerator(document);
var oldModifiersAndStatic = syntaxGenerator.GetModifiers(node).WithIsStatic(true).WithIsReadOnly(false);
var newNode = syntaxGenerator.WithModifiers(node, oldModifiersAndStatic);

The iterator modifer does not exist in C# and is not recognized here.
I am thinking the best way to do this is to add the Iterator field to DeclarationModifiers.
Unless we would add VB specific logic to analyzer but that would require them having split sources since the analyzer package doesn't directly reference language specific packages and I assume it should stay that way.

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

No branches or pull requests

1 participant