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

S3906: False positive when using generic type constraint #2423

Closed
antoinebj opened this issue May 10, 2019 · 1 comment · Fixed by #2447
Closed

S3906: False positive when using generic type constraint #2423

antoinebj opened this issue May 10, 2019 · 1 comment · Fixed by #2447
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@antoinebj
Copy link

Description

The S3906 rule "Event Handlers should have the correct signature" does not recognize generic types being constrained to EventArgs or to a subclass of it.

Repro steps

  1. Create a method or class with a generic type parameter constrained to EventArgs

  2. Use the constrained generic type as type parameter for EventHandler<> when declaring an event.

Example:

public class Foo<TEventArgs> where TEventArgs : EventArgs
{
    public event EventHandler<TEventArgs> SomethingHappened; // S3906
}

Expected behavior

No violation of the rule should be detected.

Actual behavior

A violation of the rule is detected.

Known workarounds

Suppressing the message.

Related information

  • SonarC# Version 7.14.0.8411
  • Visual Studio Version 16.0.3
@antoinebj antoinebj changed the title S3906: Rule doesn't recognize generic type constraint S3906: False positive when using generic type constraint May 10, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added this to the Support milestone May 21, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added Area: C# C# rules related issues. Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels May 22, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource removed this from the Support milestone May 22, 2019
@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented May 22, 2019

thanks, @antoinebj for the issue+reproducer. I confirm the behavior in 7.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants