Skip to content

Commit e83b5d5

Browse files
sbomerCopilot
andauthored
Add regression test for tuple swap with implicit indexer references (#132086)
## Summary Adds a regression test for #117122, a crash (`Debug.Assert` failure in `VisitImplicitIndexerReference`) hit by the ILLink Roslyn analyzer when analyzing a tuple-swap deconstruction assignment involving `Span<T>` elements accessed via the `^` (Index) operator, e.g.: ```csharp Span<int> span = stackalloc int[4]; (span[^1], span[^2]) = (span[^2], span[^1]); ``` ## Root cause `GetValueUsageInfo` returns `ValueUsageInfo.Write` (without `.Reference`) for operations on the left side of a deconstruction assignment. `VisitImplicitIndexerReference` previously asserted that any `Write`-flagged implicit indexer reference must also be `Reference`, an assumption that didn't hold for deconstruction-assignment targets. This is already fixed on `main` by #131624 ("Add dataflow support for deconstruction assignments"), which added proper `VisitDeconstructionAssignment` handling that routes deconstruction targets through dedicated assignment-processing logic instead of the generic operation visitor that could trip the old assert. That change closes #123767, and as a side effect also fixes this crash — verified by testing with only that fix applied (no separate patch needed here). ## Testing Folded the new test case (`TestTupleSwap`) into the existing `ImplicitIndexerAccess` nested test class in `PropertyDataFlow.cs`, since it already covers directly related `^`-indexer and `Span<T>` write scenarios. Verified the test: - Reproduces the crash against code prior to #131624. - Passes with #131624 applied. - Passes across all three tools that share this test-case file: the Roslyn analyzer (`ILLink.RoslynAnalyzer.Tests`), the IL trimmer (`Mono.Linker.Tests`), and NativeAOT (`ILCompiler.Trimming.Tests`). > [!NOTE] > This content was created with assistance from AI. Fixes #117122 --------- Co-authored-by: Copilot <[email protected]> Copilot-Session: fc762140-27e7-4d82-9f89-a55a3d8b7d78
1 parent 00457c4 commit e83b5d5

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,16 @@ static void TestSpanIndexerAccess(int start = 0, int end = 3)
782782
types[index].RequiresAll();
783783
}
784784

785+
// Tuple-swapping elements accessed through an implicit indexer (using the
786+
// System.Index '^' operator) used to crash the analyzer, because Roslyn
787+
// marks an implicit indexer reference that is a deconstruction assignment
788+
// target as a write without also marking it as a reference.
789+
static void TestTupleSwap()
790+
{
791+
Span<int> span = stackalloc int[4];
792+
(span[^1], span[^2]) = (span[^2], span[^1]);
793+
}
794+
785795
class IndexWithTypeWithDam
786796
{
787797
class DamOnIndexOnly
@@ -925,6 +935,7 @@ public static void Test()
925935
TestWrite();
926936
TestNullCoalescingAssignment();
927937
TestSpanIndexerAccess();
938+
TestTupleSwap();
928939
IndexWithTypeWithDam.Test();
929940
}
930941
}

0 commit comments

Comments
 (0)