-
Notifications
You must be signed in to change notification settings - Fork 128
Warn on DAM mismatch between overrides #2656
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
I agree that it would make more sense, the question is if it's worth the change. If there's an existing suppression, fixing this will break that suppression. I'm not sure the change is important enough to risk a break like that. |
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
| var methodParamHasDam = methodTypeParam.TryGetAttribute (DynamicallyAccessedMembersAttribute, out var methodTypeParamAttribute); | ||
| var overriddenParamHasDam = overriddenTypeParam.TryGetAttribute (DynamicallyAccessedMembersAttribute, out var overriddenTypeParamAttribute); | ||
| if ((methodParamHasDam && overriddenParamHasDam && !DamAttributesMatch (methodTypeParamAttribute!, overriddenTypeParamAttribute!)) | ||
| || (methodParamHasDam ^ overriddenParamHasDam)) { | ||
| context.ReportDiagnostic (Diagnostic.Create ( | ||
| DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.DynamicallyAccessedMembersMismatchOnGenericParameterBetweenOverrides), | ||
| methodTypeParam.Locations[0], | ||
| methodTypeParam.GetDisplayName (), method.GetDisplayName (), overriddenTypeParam.GetDisplayName (), overriddenMethod.GetDisplayName ())); | ||
| } |
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.
Would it be possible to refactor this to share the code between the four places? The condition and warnings are nearly identical.
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 tried to, and for me the slight differences in each case are just enough so that anything I tried ended up adding complexity without reducing repetition.
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.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
vitek-karas
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.
Some minor comments, but looks good otherwise.
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
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.
LGTM, only a few nits. Thank you!
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
* Warn on DAM mismatch between overrides Commit migrated from dotnet/linker@ac6cfb3
Fixes #2512
Adds checks to ensure that method overrides have the same DAM annotations as the virtual methods / interfaces. Warning on the implicit 'this' meant I had to add annotations to the test class that inherited from
Typeand update the expected warnings related to that class.I found that the when there is a mismatch between DAM on a property and on the accessor, the linker will warn on the accessor, but use that DAM annotation instead of the property's. I think it would make more sense to warn on the property, so the analyzer warns there, and I filed #2654 to track the issue with the linker.
Also created a helper to find all the interface members that a type implements, which also takes into account any interfaces an interface recursively implements, and updated the RequiresAnalyzer to use that helper.
Finally, updated the checks for
LogContainsandLogDoesNotContainin the analyzer tests to support Regex matches and deduplicated some code there.