Skip to content

Commit

Permalink
fix(logger): prevent logger from panicking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Aug 7, 2024
1 parent 0a4e5f1 commit bf0baa4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 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.4"
version = "1.7.5"
edition = "2021"
description = "Compiler frontend for developing great programming languages"
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ let tokens = cc.tokenize()?;

# Change log 🚀

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

## Version 1.7.4
### Fix:
- `Logger::text` now doesn't end with a new line
Expand Down
2 changes: 1 addition & 1 deletion src/compiling/failing/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Logger {
if col - 1 + len > 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 - code.chars().count();
*overflow = (col - 2 + len).checked_sub(code.chars().count()).unwrap_or(0);
}
Some(format!("{line}| {formatted}"))
}
Expand Down

0 comments on commit bf0baa4

Please sign in to comment.