Skip to content

Commit

Permalink
fix(logger): Change the order of subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Aug 7, 2024
1 parent 7701a75 commit e32a295
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heraclitus-compiler"
version = "1.7.5"
version = "1.7.6"
edition = "2021"
description = "Compiler frontend for developing great programming languages"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let tokens = cc.tokenize()?;

# Change log 🚀

## Version 1.7.5
## Version 1.7.6
### Fix:
- Prevent Logger from panicking when trying to display a region that is out of bounds

Expand Down
4 changes: 2 additions & 2 deletions src/compiling/failing/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ impl Logger {
let slices = self.get_highlighted_part(&code)?;
let formatted = format!("{}{}{}", slices[0], slices[1].color(self.kind_to_color()), slices[2]);
// If we are at the end of the code snippet and there is still some
if col - 1 + len > code.chars().count() {
if col + len - 1 > code.chars().count() {
// We substract here 2 because 1 is the offset of col (starts at 1)
// and other 1 is the new line character that we do not display
*overflow = (col - 2 + len).checked_sub(code.chars().count()).unwrap_or(0);
*overflow = (col + len - 2).checked_sub(code.chars().count()).unwrap_or(0);
}
Some(format!("{line}| {formatted}"))
}
Expand Down

0 comments on commit e32a295

Please sign in to comment.