Repository navigation
Validate a struct collection that a property holds - #84
Merged
Merged
Conversation
Unskip the 8 specs, and add specs for an object shared by two struct collections and for [SkipRecursiveValidation]. They fail until the fix is added. The guards that pin the old gap still pass. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The validator skipped every property of a struct type, so an invalid object inside an ImmutableArray property passed, while the same struct was validated as an item of a list. A property of a struct that is a collection of items that can have attributes is now enumerated. A default struct is skipped, as an item is. Delete the two guards that pinned the gap. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Specs for a struct collection whose Equals says "equal to default" while it holds invalid objects, or throws. The first group fails until IsDefaultStruct stops calling the Equals of the caller's type. Guards for a struct collection property against the maximum depth, for a dictionary value that is a struct collection, and for IsWalked and IsLeafType. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
IsDefaultStruct called the Equals of the caller's struct. A struct that compares only an Id, or has no fields, then counted as default while it held invalid objects, so the validation passed. An Equals that throws ended the validation. Compare the memory with RuntimeHelpers.Equals instead. Skip a default struct in a property only when the property is declared as a struct. A property declared as an interface or object was always enumerated, and a boxed struct in it is enumerated again. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Say "five checks" where five are listed, use 3.0 for the next release, and update the comments that said a struct collection property is not read. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
Motivation
The validator reads only the properties of reference types, so a property whose type is a struct was skipped. That included a struct collection such as ImmutableArray. The same struct was validated when it was an item of a list, since the nested collections change in #82. A model could therefore pass validation only because the collection sat one level higher, which is a false pass of the kind the 3.0 series is removing.
An independent review of everything since v2.3.3 found two bugs in the first version of this change. Both are fixed here, with specs that failed before the fix.
Summary
Not in this PR: the depth is still counted along the walk's route, so a valid graph with many back-references can fail at 128. That is a design problem in #83, and it gets its own PR (a breadth-first walk). KeyValuePair and tuple properties are also still not walked.
Test plan