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

Fix S2699 FP: Support overridden methods annotated with AssertionMethodAttribute #6652

Merged

Conversation

martin-strecker-sonarsource
Copy link
Contributor

Fixes #6525

[DataTestMethod]
[DataRow(true, true)]
[DataRow(false, true)] // The "Inherited" flag is not inherited for the AttributeUsage attribute itself. See also the SymbolHelperTest.GetAttributesWithInherited... tests,
// where the reflection behavior of MemberInfo.GetCustomAttributes is also tested.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit surprsing because AttributeUsageAttribute has Inherited = true but it seems it is not respected by GetCustomAttributes.


[DataTestMethod]
[DataRow("BaseClass`1", "MyInheritedAttribute", "MyDerivedInheritedAttribute", "MyNotInheritedAttribute", "MyDerivedNotInheritedAttribute", "MyUnannotatedAttribute")]
[DataRow("DerivedOpenGeneric`1", "MyInheritedAttribute", "MyDerivedInheritedAttribute", "MyDerivedNotInheritedAttribute", "MyUnannotatedAttribute")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here MyNotInherited is not returned by GetCustomAttributes as expected, but MyDerivedNotInherited is returned. GetCustomAttributes is the source of truth and so we need to follow that behavior here.

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Round 1 - implementation. I didn't check UTs yet

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Round 2 on implementation. Few items were skipped

@andrei-epure-sonarsource
Copy link
Contributor

@martin-strecker-sonarsource what is needed to close this one?

@martin-strecker-sonarsource
Copy link
Contributor Author

@andrei-epure-sonarsource there were only some doc comment changes left which I just fixed. Can you approve or should I ask some else from the team?

@pavel-mikula-sonarsource
Copy link
Contributor

Can you please rebase, just to avoid surprises. As this has been around for a while and it bit me recently

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Minor polishing in the UTs

@sonarcloud
Copy link

sonarcloud bot commented Mar 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Mar 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

97.2% 97.2% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM

I've converted it to draft to prevent merging before 8.54 release

@pavel-mikula-sonarsource
Copy link
Contributor

ah, master is locked, we don't need drafts anymore

@pavel-mikula-sonarsource pavel-mikula-sonarsource marked this pull request as ready for review March 3, 2023 09:55
@martin-strecker-sonarsource martin-strecker-sonarsource deleted the Martin/S2699_SupportInheritedAttributes branch March 14, 2023 09:58
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

Successfully merging this pull request may close these issues.

Fix S2699 FP: AssertionMethodAttribute is ignored when assertion method is inherited
3 participants