Fix the interpreted version of Expression<>.Compile() for setting field on value types #116901
+478
−66
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.
A bug was discovered where
Expression<>.Compile(true)
would return a different result toExpression<>.Compile(false)
. The result in the case of the interpreter meant that fields of a value type embedded within a reference type could not be set, as the interpreter was setting the fields on a boxed version of the value type.The following unit test demonstrates this functionality:
This PR fixes this issue by utilizing
TypedReference
to access the fields. A special typeFieldData
was added into theInterpretedFrame
'sData
stack which is then used to determine if the slot represents a value type field access. Externally what was exposed as an object array is now wrapped, and access unwraps to the actual object upon access.The
FieldOperations
class is the only class that is required to handle the addedFieldData
type.NOTE: Tests for the System.Linq.Expressions library had been ignored in debug builds (due to speed reasons) but I have commented out that in order that they are executed. So presumably that change would be reversed before this PR is pulled into the mainline...