Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/Rules/MA0109.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ void A(System.ReadOnlySpan<string> a) { }
````c#
void A(string[] a) { } // report diagnostic
````

The rule does not report a diagnostic for the program entry point (`Main(string[] args)`), as its signature is mandated by the runtime.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ private static void AnalyzeMethod(SymbolAnalysisContext context)
if (method.MethodKind is not MethodKind.Ordinary and not MethodKind.Constructor)
return;

// Skip the program entry point (e.g., Main(string[] args)) as the signature is mandated by the runtime
if (method.IsEqualTo(context.Compilation.GetEntryPoint(context.CancellationToken)))
return;

if (!method.Parameters.Any(IsCandidateForSpanOrMemory))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ private static ProjectBuilder CreateProjectBuilder()
.WithAnalyzer<AddOverloadWithSpanOrMemoryAnalyzer>();
}

[Fact]
public async Task EntryPoint_Main_ShouldNotTrigger()
{
const string SourceCode = """
public class Program
{
public static void Main(string[] args) { }
}
""";
await CreateProjectBuilder()
.WithOutputKind(Microsoft.CodeAnalysis.OutputKind.ConsoleApplication)
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task EntryPoint_NonMainMethod_ShouldTrigger()
{
const string SourceCode = """
public class Program
{
public static void Main(string[] args) { }
public static void [|DoWork|](string[] data) { }
}
""";
await CreateProjectBuilder()
.WithOutputKind(Microsoft.CodeAnalysis.OutputKind.ConsoleApplication)
.WithSourceCode(SourceCode)
.ValidateAsync();
}

[Fact]
public async Task StringArrayWithoutSpanOverload_Params()
{
Expand Down
Loading