Document Expression.Block ReadOnlyCollection reuse#12754
Open
YNan-varamor wants to merge 1 commit into
Open
Conversation
Contributor
|
Tagging subscribers to this area: @cston |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the .NET API reference documentation for System.Linq.Expressions.Expression.Block to warn about a longstanding behavior where certain overloads can reuse caller-provided collections, which can lead to surprising results if the underlying storage is mutated after the block is created.
Changes:
- Added remarks warning that
Expression.Blockoverloads takingIEnumerable<Expression>might reuse a providedReadOnlyCollection<Expression>instance. - Added guidance advising callers not to mutate underlying storage and to take a stable snapshot when the source can change.
- Replaced placeholder remarks (“To be added.”) with markdown remarks content for additional overloads.
Comment on lines
+2703
to
+2710
| <remarks> | ||
| <format type="text/markdown"><![CDATA[ | ||
|
|
||
| ## Remarks | ||
| If you pass a <xref:System.Collections.ObjectModel.ReadOnlyCollection%601> instance as the `expressions` argument, the returned <xref:System.Linq.Expressions.BlockExpression> might reuse that collection instead of copying it. Do not modify the collection's underlying storage after creating the block. If the source can be mutated, create a stable snapshot before passing it to this method. | ||
|
|
||
| ]]></format> | ||
| </remarks> |
Member
There was a problem hiding this comment.
@YNan-varamor please address this comment. The other comments are bogus, but this is correct.
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
Motivation
Addresses #12691. The runtime behavior discussed in dotnet/runtime#128813 is longstanding, so this adds the requested documentation warning rather than changing behavior.
Validation
Disclosure
Prepared with assistance from OpenAI Codex.