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 S3220 FP: Rule does not take into account generics #8522

Closed
RenderMichael opened this issue Jan 8, 2024 · 1 comment · Fixed by #9389
Closed

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

RenderMichael opened this issue Jan 8, 2024 · 1 comment · Fixed by #9389
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@RenderMichael
Copy link

RenderMichael commented Jan 8, 2024

Description

The following code produces a S3220 warning at the Caller.Test<T>(string key) method, even though the generic parameter is crucial to the method's execution.

Repro steps

internal static class Called
{
    public static T? Get<T>(params string[] key)
    {
        ArgumentNullException.ThrowIfNull(key);
        return default;
    }

    public static string? Get(string key)
    {
        ArgumentNullException.ThrowIfNull(key);
        return default;
    }
}

internal static class Caller
{
    public static T? Test<T>(string key)
    {
        return Called.Get<T>(key);
    }
}

Expected behavior

No warning.

Actual behavior

Warning.

Known workarounds

Not without violating S3878.

Related information

I'm using the Visual Studio extension, version 7.5.0.82292

@Tim-Pohlmann
Copy link
Contributor

Hi @RenderMichael, very good catch! We will address this in a future hardening sprint. Thanks for the report!

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. Area: VB.NET VB.NET 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.

4 participants