Skip to content

Fix S3878 FP: Jagged arrays #8163

@ThorstenReichert

Description

@ThorstenReichert

Description

When a C# method has an array of arrays as params parameter, S3878 is raised when the method is called. e.g. for

public class Repro8163
{
    public static void Method(params object[][] array) { }

    public static void CallParamsMethod()
    {
        Method(new[] { new object() }); // Noncompliant - FP
    }
}

Following the S3878 suggestion to "remove the array creation and simply pass the elements" will result in a compiler error (type mismatch "cannot convert from object to object[]").

Expected behavior

No issue is raised.

Actual behavior

S3878 is raised.

Known workarounds

Move the array creation to a separate variable, then pass that variable as method parameter.

Related information

  • Visual Studio version: 17.6.1
  • MSBuild / dotnet version: .NET 7
  • SonarScanner for .NET version: Sonar Server Version 9.9.1 (build 69595) / SonarLint Version 7.3.0.77872
  • Operating System: Windows 10

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