Fix MA0123 checking the wrong argument when the arguments are named

Merged
ME
2mo ago
+22-7

What

MA0123 (Sequence number must be a constant) read the sequence argument by position (Arguments[0] / Arguments[1]). IInvocationOperation.Arguments is in evaluation order, which is the written order when the arguments are named, so the rule checked the wrong argument:

builder.AddContent(textContent: "a" + param, sequence: 0);

Expected: no diagnostic. Actual: MA0123 on "a" + param. Conversely, builder.AddContent(textContent: default(string), sequence: value++) was not reported.

Fix

The analyzer finds the sequence argument by the ordinal of its parameter (0 for the RenderTreeBuilder methods, 1 for the WebRenderTreeBuilderExtensions extension methods) instead of by position.

Tests

Added named-argument cases to the Valid and Variable theories of SequenceNumberMustBeAConstantAnalyzerTests, for both a RenderTreeBuilder method and a WebRenderTreeBuilderExtensions method (all 4 failed before the fix). The test class passes on roslyn5.9 (58/58) and roslyn4.8 (58/58).