Skip to content

Commit

Permalink
Fix another weird panic in scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
rctcwyvrn committed Aug 13, 2020
1 parent f69ae64 commit e86ed3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/while_true.lox
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
while(true){
print("hi"); // BUG: The current implementation cannot have a while loop as the first parsed expression, because it cannot jump back to instruction 0...
}
2 changes: 1 addition & 1 deletion src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Scanner<'_> {

/// One stricter than is_at_end, must be checked before calling peek_next()
fn can_peek_next(&self) -> bool {
self.cur_pos <= self.code.len() - 2
self.cur_pos + 2 <= self.code.len() // +2 because self.code.len() does not necesarily need to be greater than 2, and subtracting can cause a panic
}

fn advance(&mut self) -> u8 {
Expand Down

0 comments on commit e86ed3b

Please sign in to comment.