Skip to content

Commit

Permalink
S3878: Add FP repro for #8510 (#8511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource authored Jan 3, 2024
1 parent 3ccd115 commit 2fb41a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,7 @@ public void ArrayPassedAsParams_CSharp9() =>

[TestMethod]
public void ArrayPassedAsParams_CSharp12() =>
builderCS.AddSnippet("""
_ = new MyClass(1, [1, 2, 3]); // Noncompliant
_ = new MyClass(1, []); // Noncompliant
_ = new MyClass2([1], [1, 2, 3]); // Noncompliant
_ = new MyClass2([1, 2, 3], 1);
_ = new MyClass3([1, 2, 3], [4, 5, 6]); // Noncompliant FP
_ = new MyClass3([[1, 2, 3], [4, 5, 6]]); // Noncompliant
class MyClass(int a, params int[] args);
class MyClass2(int[] a, params int[] args);
class MyClass3(params int[][] args);
""")
builderCS.AddPaths("ArrayPassedAsParams.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.WithTopLevelStatements()
.Verify();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

const int a = 1;
int[] array = [2, 3];

_ = new MyClass(1, [1, 2, 3]); // Noncompliant
_ = new MyClass(1, []); // Noncompliant

// repro for https://github.com/SonarSource/sonar-dotnet/issues/8510
_ = new MyClass(1, [a, .. array]); // Noncompliant FP

_ = new MyClass2([1], [1, 2, 3]); // Noncompliant
_ = new MyClass2([1, 2, 3], 1);
_ = new MyClass3([1, 2, 3], [4, 5, 6]); // Noncompliant FP
_ = new MyClass3([[1, 2, 3], [4, 5, 6]]); // Noncompliant
_ = new MyClass3([[1, 2, 3], [4, 5, 6]]); // Noncompliant

class MyClass(int a, params int[] args);
class MyClass2(int[] a, params int[] args);
class MyClass3(params int[][] args);

0 comments on commit 2fb41a4

Please # to comment.