-
Notifications
You must be signed in to change notification settings - Fork 128
DynamicallyAccessedMembers CodeFix #2890
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
Conversation
iserrato
commented
Jul 12, 2022
- Reorganized the DAM CodeFix to not rely on 'BaseAttributeCodeFixProvider`, as the DAM CodeFix requires different functionality for placing attributes on parameters, returns, etc.
- Create test cases for supported Diagnostic IDs
Merge the base class and the codefixer add a test for codefix incomplete: edit codefix to get source syntaxnode
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Andy Gocke <[email protected]>
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/RequiresUnreferencedCodeAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
- remove unsupported diagnostics from `SupportedDiagnostics` list - remove unused functions/variables - remove unneccessary comments
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
tlakollo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor things, I think in general looks good
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
| var diagnostic = context.Diagnostics.First (); | ||
| var props = diagnostic.Properties; | ||
| var model = await document.GetSemanticModelAsync (context.CancellationToken).ConfigureAwait (false); | ||
| SyntaxNode diagnosticNode = root!.FindNode (diagnostic.Location.SourceSpan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please apply the fix from https://github.com/dotnet/linker/pull/2900/files here? If I understood that fix, I think it may matter for example in the case where a method invocation is passed as an argument, like:
static void M([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t)
{
DoSomethingWithMethods(t.GetMethods());
}Maybe @agocke can confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add a test case associated with this fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please! Best would be to confirm that the testcase produces an incorrect result before the fix, and then check that it works with the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that's exactly what my change fixes. I would agree -- creating a test case, confirming it throws an exception, then applying the fix and confirming it no longer does so is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, actually it looks like diagnosticNode is properly null checked below, so it won't throw an exception. Probably just won't work (the type will be ArgumentSyntax instead of InvocationExpressionSyntax).
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersCodeFixTests.cs
Outdated
Show resolved
Hide resolved
test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
Show resolved
Hide resolved
sbomer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more comment and this LGTM. Thank you!
|
|
||
| namespace ILLink.CodeFix | ||
| { | ||
| public class DAMCodeFixProvider : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this won't work in Visual Studio. You need to have [ExportCodefixProvider(LanguageNames.CSharp), Shared] on the class. Opened #2932
* Create infrastructure for CodeFixers that will generate attribute flags for DynamicallyAccessedMembers (DAM) trimmer warnings. This commit includes fixers for the warnings `DynamicallyAccessedMembersMismatchParameterTargetsThisParameter` and `DynamicallyAccessedMembersMismatchFieldTargetsThisParameter`. Additional DiagnosticIds will be supported by future commits. * Create new class for the DAM CodeFixer that does not rely on base class. The DAM warnings require different attribute placement depending on the type of warning that is raised, causing it to differ from the implementation of the base class. * Added a test file specifically for the DAM CodeFixer, include tests for the functional fixes as well as tests for fixes that will soon be implemented. * Converted all test cases within DAM to use string literals Co-authored-by: Andy Gocke <[email protected]> Commit migrated from dotnet/linker@8062da2