Skip to content

Fix S3220 FP: Rule does not take into account generics#9389

Merged
mary-georgiou-sonarsource merged 3 commits intomasterfrom
mary/FP-S3220-params
Jun 5, 2024
Merged

Fix S3220 FP: Rule does not take into account generics#9389
mary-georgiou-sonarsource merged 3 commits intomasterfrom
mary/FP-S3220-params

Conversation

@mary-georgiou-sonarsource
Copy link
Contributor

Fixes #8522

Copy link
Contributor

@zsolt-kolbay-sonarsource zsolt-kolbay-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

{
Get<string>("text"); // Noncompliant FP
Get<string>("text"); // Compliant
GetBothHaveGenerics<string>(1); // Compliant, when both methods are generic it seems to resolving correctly to the T GetBothHaveGenerics<T>(int anInt).
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test case where one of the generic methods has an object parameter:

T Generics<T>(params int[] ints) => default;
T Generics<T>(object anInt) => default;
...
Generics<string>(1);   // Noncompliant

{
Get<string>("text"); // Noncompliant FP
Get<string>("text"); // Compliant
GetBothHaveGenerics<string>(1); // Compliant, when both methods are generic it seems to resolving correctly to the T GetBothHaveGenerics<T>(int anInt).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GetBothHaveGenerics<string>(1); // Compliant, when both methods are generic it seems to resolving correctly to the T GetBothHaveGenerics<T>(int anInt).
GetBothHaveGenerics<string>(1); // Compliant, when both methods are generic, it seems to resolve correctly to the T GetBothHaveGenerics<T>(int anInt).

@mary-georgiou-sonarsource mary-georgiou-sonarsource enabled auto-merge (squash) June 5, 2024 09:14
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Fix S3220 FP: Rule does not take into account generics #8522 Fix S3220 FP: Rule does not take into account generics Jun 5, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource enabled auto-merge (squash) June 5, 2024 09:15
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 5, 2024

Quality Gate Passed Quality Gate passed for 'Sonar .NET Java Plugin'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 5, 2024

@mary-georgiou-sonarsource mary-georgiou-sonarsource merged commit 224dfe2 into master Jun 5, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource deleted the mary/FP-S3220-params branch June 5, 2024 09:43
@mary-georgiou-sonarsource mary-georgiou-sonarsource restored the mary/FP-S3220-params branch June 6, 2024 09:02
@mary-georgiou-sonarsource mary-georgiou-sonarsource deleted the mary/FP-S3220-params branch July 4, 2024 15:17
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 S3220 FP: Rule does not take into account generics

2 participants