Extensions: fix RemoveUnusedMember scenarios#81754
Conversation
| { | ||
| symbolStartContext.RegisterSymbolEndAction(symbolEndContext => OnSymbolEnd(symbolEndContext, hasUnsupportedOperation)); | ||
| } |
There was a problem hiding this comment.
| { | |
| symbolStartContext.RegisterSymbolEndAction(symbolEndContext => OnSymbolEnd(symbolEndContext, hasUnsupportedOperation)); | |
| } | |
| symbolStartContext.RegisterSymbolEndAction(symbolEndContext => OnSymbolEnd(symbolEndContext, hasUnsupportedOperation)); | |
| ``` #ByDesign |
There was a problem hiding this comment.
I kept those braces as neither the condition nor the branch are simple, so find this this easier to read
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
| { | |
| return false; | |
| } | |
| return false; |
Also, consider a comment above the if. but ok if not present. #Resolved
| { | ||
| yield return extensionMember; | ||
| } |
There was a problem hiding this comment.
| { | |
| yield return extensionMember; | |
| } | |
| yield return extensionMember; | |
| ``` #Resolved |
| if (extensionBlockMethod.AssociatedSymbol is { } associatedSymbol) | ||
| { | ||
| AddIfCandidateSymbol(builder, associatedSymbol); | ||
| } |
There was a problem hiding this comment.
| if (extensionBlockMethod.AssociatedSymbol is { } associatedSymbol) | |
| { | |
| AddIfCandidateSymbol(builder, associatedSymbol); | |
| } | |
| AddIfCandidateSymbol(builder, extensionBlockMethod.AssociatedSymbol); | |
| ``` #Resolved |
| foreach (var extensionMember in extensionBlock.Members) | ||
| { | ||
| yield return extensionMember; | ||
| } |
There was a problem hiding this comment.
| foreach (var extensionMember in extensionBlock.Members) | |
| { | |
| yield return extensionMember; | |
| } | |
| foreach (var extensionMember in extensionBlock.Members) | |
| yield return extensionMember; | |
| ``` #Resolved |
| FixedCode = code, | ||
| LanguageVersion = LanguageVersion.CSharp14, | ||
| }.RunAsync(); | ||
| } |
There was a problem hiding this comment.
you can just inline 'code' and remove the 'fixedcode=code' line in all of these. then make the methods not async/awit. but instead just return the new Test { ... }.RunAsync(); #Resolved
| if (associated is null) | ||
| continue; |
There was a problem hiding this comment.
| if (associated is null) | |
| continue; | |
| ``` #Resolved |
There was a problem hiding this comment.
Sorry, I'd misunderstood the suggestion in previous PR because of how the diff is shown in CodeFlow...
Fixes #80645 and related issues #81213 and #81657
The principle of
AbstractRemoveUnusedMembersDiagnosticAnalyzeris that we respond to member declarations by registering them (AnalyzeSymbolDeclaration), then analyze various references (invocations, member references, deconstructions, nameof, cref, etc), then when we exit the type we can report private unused members.The change is that we treat extension members as part of the enclosing static class:
Additionally, any usage of disambiguation syntax marks the corresponding extension member as "used".