Browse Source

Add regression test for duplicate array-element assignment

A second store to an already-written array element must prevent
HandleSimpleArrayInitializer from folding the stores into a collection
initializer: the earlier store would be dropped (a visible change when
its value has side effects), and without the nextMinimumIndex guard the
transform crashes on the colliding index. The nextMinimumIndex check
already enforces this; pin it with a Pretty fixture so the boundary
between a foldable initializer and a duplicate-write sequence stays
covered.

Assisted-by: Claude:claude-fable-5:Claude Code
master
Siegfried Pammer 14 hours ago committed by Siegfried Pammer
parent
commit
52e2161ea7
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

13
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -515,6 +515,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
X(Y(), new int[5] { a, 0, b, 0, c }); X(Y(), new int[5] { a, 0, b, 0, c });
} }
public static int[] DuplicateElementAssignment()
{
// A second store to an element that was already written must stop the array-initializer
// transform from folding these stores into a 'new int[] { ... }'. Doing so would drop the
// earlier store, which is a visible change when its value has side effects.
int[] array = new int[3];
array[0] = 1;
array[0] = 2;
array[1] = 3;
array[2] = 4;
return array;
}
public static void NestedArray(int a, int b, int c) public static void NestedArray(int a, int b, int c)
{ {
X(Y(), new int[3][] { X(Y(), new int[3][] {

Loading…
Cancel
Save