Skip to content

Commit

Permalink
code smell and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jun 6, 2024
1 parent 7067bde commit 4059423
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ bool ParamArgumentsAreReferenceTypeArrays(SyntaxNode node, IMethodSymbol symbol,
&& ArrayElementType(arguments.First(), model) is { } elementType
&& elementType.IsReferenceType
&& !elementType.Is(KnownType.System_Object);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,21 @@ public void Method(params object[] args) { }
public void MethodArray(params Array[] args) { }
public void MethodJaggedArray(params int[][] args) { }

public void CallMethod()
public void CallMethod(dynamic d)
{
Method(new String[] { "1", "2" }); // Noncompliant, elements in args: ["1", "2"]
// The argument given for a parameter array can be a single expression that is implicitly convertible (§10.2) to the parameter array type.
// In this case, the parameter array acts precisely like a value parameter.
// see: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#14625-parameter-arrays
Method(new object[] { new int[] { 1, 2} }); // FN, elements in args: [System.Int32[]]
Method(new object[] { new int[] { 1, 2 } }); // FN, elements in args: [System.Int32[]]
Method(new int[] { 1, 2, 3, }); // Compliant, Elements in args: [System.Int32[]]
Method(new String[] { "1", "2" }, new String[] { "1", "2"}); // Compliant, elements in args: [System.String[], System.String[]]
Method(new String[] { "1", "2" }, new String[] { "1", "2" }); // Compliant, elements in args: [System.String[], System.String[]]
Method(new String[] { "1", "2"}, new int[] { 1, 2}); // Compliant, elements in args: pSystem.String[], System.Int32[]]
MethodArray(new String[] { "1", "2" }, new String[] { "1", "2" }); // Compliant, elements in args: [System.String[], System.String[]]
MethodArray(new int[] { 1, 2 }, new int[] { 1, 2 }); // Compliant, elements in args: [System.Int32[], System.Int32[]]

MethodJaggedArray(new int[] { 1, 2 }); // Compliant: jagged array [System.Object[]]
Method(d); // For coverage

string.Format(CultureInfo.InvariantCulture, "{0}.{1}", new object[] { "", new object() });
}
Expand Down

0 comments on commit 4059423

Please sign in to comment.