Conversation
Add Descendants and DescendantsAndSelf overloads taking a descendIntoChildren predicate to OperationExtensions, enabling callers to prune operation tree traversal. Fixes dotnet#53621
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 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
|
This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging. |
333fred
reviewed
Oct 2, 2026
Comment on lines
+430
to
+436
| // The anonymous function itself is yielded | ||
| Assert.Contains(prunedDescendants, op => op is IAnonymousFunctionOperation); | ||
| // But operations inside the lambda (like literal '2') are pruned | ||
| Assert.DoesNotContain(prunedDescendants, op => op is ILiteralOperation { ConstantValue: { HasValue: true, Value: 2 } }); | ||
| // And operations outside the lambda (literal '1' and '3') are present | ||
| Assert.Contains(prunedDescendants, op => op is ILiteralOperation { ConstantValue: { HasValue: true, Value: 1 } }); | ||
| Assert.Contains(prunedDescendants, op => op is ILiteralOperation { ConstantValue: { HasValue: true, Value: 3 } }); |
Member
There was a problem hiding this comment.
Let's just directly assert the operations in the list.
Author
There was a problem hiding this comment.
Updated to directly assert the exact sequence of OperationKinds in prunedDescendants.
This branch has not been deployed
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.
Fixes #53621
Summary
Adds overloads for
IOperation.DescendantsandIOperation.DescendantsAndSelfaccepting an optionalFunc<IOperation, bool>? descendIntoChildrenpredicate, as approved in API review (#53621).API Changes
Details
OperationExtensions.Descendantstraversal to checkdescendIntoChildren(operation)on the root (yielding the root ifincludeSelf: true, but pruning child traversal iffalse), anddescendIntoChildren(current)before pushing children of traversed operations.descendIntoChildrenis null (the parameterless overloads forwarddescendIntoChildren: null).src/Compilers/Core/Portable/PublicAPI.Unshipped.txt.OperationTests.csverifying null operation handling, null predicate equivalence, lambda/local function pruning, and root pruning semantics.Microsoft Reviewers: Open in CodeFlow