-
Notifications
You must be signed in to change notification settings - Fork 228
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 S4144 FP: when type constraints are used #9398
Conversation
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.
Partial Review
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
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.
Review complete, only one minor thing in addition to the first pass.
...s/tests/SonarAnalyzer.Test/TestCases/MethodsShouldNotHaveIdenticalImplementations.CSharp9.cs
Outdated
Show resolved
Hide resolved
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.
This PR is quite the journey :D
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.TestFramework/Common/CombinatorialDataAttribute.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
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.
Looks very good but can be simplified more.
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/MethodsShouldNotHaveIdenticalImplementationsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/MethodsShouldNotHaveIdenticalImplementationsTest.cs
Show resolved
Hide resolved
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.
Looks good. I added a comment why I think the simplification of the previous review is possible. Please take another look before merging.
I did quite some rewrite and so I better ask for review again.. |
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.
Very nice refactor!
first.Equals(second) // M1<T>(T x) where T: IComparable <-> M2<T>(T x) where T: IComparable | ||
|| AreSameNamedTypeParameters(first, second) // M1<T1, T2>() where T1: T2 <-> M2<T1, T2>() where T1: T2 | ||
// T2 of M1 is a different symbol than T2 of M2, but if they have the same name they can be interchanged. | ||
// T2 equivalency is checked as well in HaveSameTypeParameters |
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.
This comment is outdated, HaveSameTypeParameters
doesn't exist anymore.
&& first.ConstraintTypes.All(x => second.ConstraintTypes.Any(y => TypesAreSame(x, y))); | ||
&& first.ConstraintTypes.All(x => second.ConstraintTypes.Any(y => TypeConstraintsAreSame(x, y))); | ||
|
||
private static bool TypeConstraintsAreSame(ITypeSymbol first, ITypeSymbol second) => |
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.
This name confuses me a bit. It makes sense when called from TypeParametersHaveSameNameAndConstraints
but does not seem accurate when called from TypesAreSameGenericType
.
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. That is right, but I couldn't come up with a better name.
Quality Gate passed for 'Sonar .NET Java Plugin'Issues Measures |
Quality Gate passed for 'SonarAnalyzer for .NET'Issues Measures |
Peach validation: One FN found in https://peach.aws-prd.sonarsource.com/code?id=servuo&selected=servuo:Server/Serialization.cs&line=963 public override void WriteMobileList<T>(List<T> list, bool tidy)
public override void WriteItemList<T>(List<T> list, bool tidy) Both methods have the same body and were detected before as duplicates. With the new logic, the issue seems to get lost. |
Correction: These are TNs, as the generic constraints are defined on the virtual/abstract method but not on the override. I will add a reproducer, nevertheless, as this is only detectable by semantic checks. |
Fixes #7068