Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Update edited document before continuing code fixing - #2250

Merged
mateoatr merged 2 commits into
dotnet:mainfrom
mateoatr:codeFixer
Sep 7, 2021
Merged

mateoatr merged 2 commits into
dotnet:mainfrom
mateoatr:codeFixer

Conversation

@mateoatr

@mateoatr mateoatr commented Sep 2, 2021

Copy link
Copy Markdown
Contributor

Fixes #2149.

var attributeArguments = GetAttributeArguments (SyntaxGenerator.GetGenerator (document), targetSymbol, diagnostic);
var codeFixTitle = CodeFixTitle.ToString ();

context.RegisterCodeFix (CodeAction.Create (codeFixTitle,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you preserve the earlier formatting? It's longer but clearer about what argument belongs to each method call

// /0/Test0.cs(24,31): warning IL2026: Using member 'C.M1()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. message.
VerifyCS.Diagnostic (DiagnosticId.RequiresUnreferencedCode).WithSpan (24, 31, 24, 37).WithArguments ("C.M1()", " message.", "")
}, new[] {
// /0/Test0.cs(27,10): error CS7036: There is no argument given that corresponds to the required formal parameter 'message' of 'RequiresUnreferencedCodeAttribute.RequiresUnreferencedCodeAttribute(string)'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these results were correct -- we don't want to fill in the message for public members, since that message will be visible to external users. The code owner should be responsible for writing a message for their public APIs.

@agocke

agocke commented Sep 4, 2021 •

Copy link
Copy Markdown
Member

OK I finally figured this out -- the problem is not the lack of a FixAll Provider, it's that the SyntaxEditor is shared via lambda capturing among multiple different invocations of the analyzer. Since the SyntaxEditor is mutable, this causes a race in addition attributes to the tree.

Your change fixes the problem by avoiding sharing the editor instance across multiple invocations.

It's probably hard to write a test to reveal this problem (and probably not worth it to write one). If you can narrow down the fix to just that area I think we should take this for 6.0

@agocke agocke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from minor suggestions

@mateoatr
mateoatr merged commit 23f5f59 into dotnet:main Sep 7, 2021
@agocke

agocke commented Sep 8, 2021

Copy link
Copy Markdown
Member

@mateoatr Can you backport to 6.0?

mateoatr added a commit to mateoatr/linker that referenced this pull request Sep 8, 2021
agocke pushed a commit that referenced this pull request Sep 8, 2021
Backport of #2250

Applying code fixes suggested by our fixer was causing multiple applications of the same fix (see here). This was caused by a race condition due to sharing the same instance of a SyntaxEditor across multiple invocations (see comment).
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
)

* PR feedback

* Remove unnecessary method

Commit migrated from dotnet/linker@23f5f59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IL2026 should use custom fix all provider

2 participants