Repository navigation
Commit e83b5d5
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-a55a3d8b7d781 parent 00457c4 commit e83b5d5
1 file changed
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
785 | 795 | | |
786 | 796 | | |
787 | 797 | | |
| |||
925 | 935 | | |
926 | 936 | | |
927 | 937 | | |
| 938 | + | |
928 | 939 | | |
929 | 940 | | |
930 | 941 | | |
| |||
0 commit comments