Skip to content

Commit 21ce254

Browse files
fix: do not push expectation errors to EOF (#539)
1 parent 414078f commit 21ce254

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

.sqlx/query-aced4382cedbfc359bb1c1ab71cf2472fa8afc0b24bf02ee1bfdfdbf111acfc8.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgt_lexer/src/lexed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Lexed<'_> {
9292
}
9393

9494
pub(crate) fn text_range(&self, i: usize) -> TextRange {
95-
assert!(i < self.len());
95+
assert!(i < self.len() - 1);
9696
let lo = self.start[i];
9797
let hi = self.start[i + 1];
9898
TextRange::new(lo.into(), hi.into())

crates/pgt_statement_splitter/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,12 @@ values ('insert', new.id, now());",
553553
"select\n email,\n\n\n from\n auth.users;",
554554
]);
555555
}
556+
557+
#[test]
558+
fn does_not_panic_on_eof_expectation() {
559+
Tester::from("insert").expect_errors(vec![SplitDiagnostic::new(
560+
"Expected INTO_KW".to_string(),
561+
TextRange::new(0.into(), 6.into()),
562+
)]);
563+
}
556564
}

crates/pgt_statement_splitter/src/splitter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,15 @@ impl<'a> Splitter<'a> {
168168
if self.current() == kind {
169169
self.advance();
170170
} else {
171+
let token = if self.current() == SyntaxKind::EOF {
172+
self.current_pos - 1
173+
} else {
174+
self.current_pos
175+
};
176+
171177
self.errors.push(SplitError {
172178
msg: format!("Expected {:#?}", kind),
173-
token: self.current_pos,
179+
token,
174180
});
175181
}
176182
}

0 commit comments

Comments
 (0)