Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ private bool TryGetFormatInfo(IMethodSymbol method, int formatIndex, [NotNullWhe
return false;
}

if (formatIndex == method.Parameters.Length - 1)
{
// format specification is the last parameter (e.g. CompositeFormat.Parse)
// this is therefore not a formatting method.
return false;
}

int expectedArguments = GetExpectedNumberOfArguments(method.Parameters, formatIndex);
formatInfo = new Info(formatIndex, expectedArguments);
_map.TryAdd(method, formatInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,36 @@ End Class"
await basicTest.RunAsync();
}

[Fact]
[WorkItem(90357, "https://github.com/dotnet/runtime/issues/90357")]
public async Task CA2241CSharpPassingMethodWithNoPossibleArguments()
{
var csharpTest = new VerifyCS.Test
{
TestState =
{
Sources =
{
@"
using System.Diagnostics.CodeAnalysis;

class Test
{
public static int Parse([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format) => -1;

void M1(string param)
{
var a = Parse(""{0} {1}"");
}
}"
},
ReferenceAssemblies = ReferenceAssemblies.Net.Net70,
}
};

await csharpTest.RunAsync();
}

#endregion

private static DiagnosticResult GetCSharpResultAt(int line, int column)
Expand Down