Browse Source

apply review comment: Make sure we don't generate broken span when retrieving the span between two other spans

Tamo 1 week ago
parent
commit
7e17ca0dbe
1 changed files with 4 additions and 1 deletions
  1. 4 1
      numbat/src/span.rs

+ 4 - 1
numbat/src/span.rs

@@ -58,9 +58,12 @@ impl Span {
     #[inline]
     pub fn in_between(left: Span, right: Span) -> Span {
         debug_assert_eq!(left.code_source_id, right.code_source_id);
+        debug_assert!(left.end <= right.start);
         crate::span::Span {
             start: left.end,
-            end: right.start,
+            // The right.start must be > left.end. But just in case it is not
+            // we'll make the new span points to left.end
+            end: right.start.max(left.end),
             // lhs and rhs should share the same code_source_id
             code_source_id: left.code_source_id,
         }