Add regression test for tuple swap with implicit indexer references - #132086
Merged
Conversation
Adds a case to the existing ImplicitIndexerAccess dataflow test in PropertyDataFlow.cs, covering the pattern from dotnet#117122, where a tuple swap involving Span<T> elements accessed via the ^ (Index) operator used to crash the ILLink Roslyn analyzer with a Debug.Assert failure in VisitImplicitIndexerReference. This is now fixed by the deconstruction assignment dataflow support added for dotnet#123767, so no additional product change is needed; this just locks in the fix with a regression test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fc762140-27e7-4d82-9f89-a55a3d8b7d78
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds regression coverage to prevent an ILLink Roslyn analyzer crash when analyzing tuple-swap deconstruction assignments that target Span<T> elements accessed via the ^ (Index) operator, matching the scenario from #117122.
Changes:
- Add a new
TestTupleSwapcase covering(span[^1], span[^2]) = (span[^2], span[^1])within the existingImplicitIndexerAccesscoverage. - Invoke
TestTupleSwapfrom the nestedImplicitIndexerAccess.Test()entrypoint to keep it exercised consistently across tool suites using this file.
Show a summary per file
| File | Description |
|---|---|
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs | Adds a regression test case for tuple-swap deconstruction with implicit indexer (^) access on Span<T>. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Reword the explanatory comment to precisely describe the root cause: Roslyn marks an implicit indexer reference that is a deconstruction assignment target as a write without also marking it as a reference, rather than the previous "not a byref" phrasing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fc762140-27e7-4d82-9f89-a55a3d8b7d78
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs:788
- The comment is slightly inaccurate:
^is the C# index-from-end operator (which produces aSystem.Index), not an operator onSystem.Indexitself. Rewording avoids confusion for future maintainers.
// Tuple-swapping elements accessed through an implicit indexer (using the
// System.Index '^' operator) used to crash the analyzer, because Roslyn
// marks an implicit indexer reference that is a deconstruction assignment
// target as a write without also marking it as a reference.
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs:791
TestTupleSwapreads fromspan[^1]/span[^2]on the RHS, but thestackalloc int[4]buffer is left uninitialized. Initializing avoids reading uninitialized stack data while still exercising the same implicit-indexer/deconstruction pattern.
Span<int> span = stackalloc int[4];
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
sbomer
enabled auto-merge (squash)
August 10, 2026 23:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a regression test for #117122, a crash (
Debug.Assertfailure inVisitImplicitIndexerReference) hit by the ILLink Roslyn analyzer when analyzing a tuple-swap deconstruction assignment involvingSpan<T>elements accessed via the^(Index) operator, e.g.:Root cause
GetValueUsageInforeturnsValueUsageInfo.Write(without.Reference) for operations on the left side of a deconstruction assignment.VisitImplicitIndexerReferencepreviously asserted that anyWrite-flagged implicit indexer reference must also beReference, an assumption that didn't hold for deconstruction-assignment targets.This is already fixed on
mainby #131624 ("Add dataflow support for deconstruction assignments"), which added properVisitDeconstructionAssignmenthandling 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 existingImplicitIndexerAccessnested test class inPropertyDataFlow.cs, since it already covers directly related^-indexer andSpan<T>write scenarios. Verified the test: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