Skip to content

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

@RenderMichael

Description

@RenderMichael

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

Metadata

Metadata

Labels

False PositiveRule IS triggered when it shouldn't be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions