Fix crash when using keypaths on final classes in Predicates #1475
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.
This predicate code validates that the provided
KeyPathonly contains a single component. Originally, for stored property components, this code checked the payload value to see if it was an inline offset or the out-of-line sentinel defined by the KeyPath ABI documentation to determine if the buffer size matches the expected single component buffer size. However, this document was determined to be incorrect and there are actually multiple sentinel values defined. #216 attempted to correct this by switching toMemoryLayout.offset(of:)to check for a single stored property component. However,MemoryLayout.offset(of:)is also not an appropriate way to check for a single stored property component as not all single stored components have offsets (for example, a property in a final class).This changes the implementation back to the original style of check before #216 but with a corrected check for whether the offset is stored inline (based on the existence of multiple sentinel values and the max inline offset defined here). This fixes the regression caused for final class properties while still ensuring that we respect other sentinel values as well.
Resolves #1173