fix(core): date parsing ordering violation #859
Merged
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.
Greptile Overview
Greptile Summary
Fixed a critical Ord trait violation in the
Valueenum's comparison implementation. Previously, incomparable types (e.g.,Datevs non-parseableString, or mismatched variants) returnedOrdering::Equal, which violates Rust's Ord contract sincea.cmp(b) == Equalshould only occur whena == b.Changes:
variant_order()helper method that assigns a deterministic u8 ordering value to each Value variantOrdering::Equalfallback cases withself.variant_order().cmp(&other.variant_order())Impact:
This fix prevents subtle bugs in any code that relies on sorting or ordering Value types, particularly when dealing with heterogeneous data.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Caller participant Value_Ord participant variant_order Caller->>Value_Ord: cmp(self, other) alt Same type comparison Value_Ord->>Value_Ord: Direct comparison (String, Date, etc.) Value_Ord-->>Caller: Ordering result else Integer types Value_Ord->>Value_Ord: Convert to i128 and compare Value_Ord-->>Caller: Ordering result else Date ↔ String Value_Ord->>Value_Ord: Try parse String as Date alt Parse successful Value_Ord->>Value_Ord: Compare dates Value_Ord-->>Caller: Ordering result else Parse failed (NEW) Value_Ord->>variant_order: Get variant order for self Value_Ord->>variant_order: Get variant order for other variant_order-->>Value_Ord: u8 ordering values Value_Ord->>Value_Ord: Compare u8 values Value_Ord-->>Caller: Deterministic ordering end else Incomparable types (NEW) Value_Ord->>variant_order: Get variant order for self Value_Ord->>variant_order: Get variant order for other variant_order-->>Value_Ord: u8 ordering values Value_Ord->>Value_Ord: Compare u8 values Value_Ord-->>Caller: Deterministic ordering end