From e32a29564ecb6d2d1c015c12fe8ee9589f404e9c Mon Sep 17 00:00:00 2001 From: Phoenix Himself Date: Wed, 7 Aug 2024 19:13:35 +0200 Subject: [PATCH] fix(logger): Change the order of subtraction --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/compiling/failing/logger.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6872b7b..8d71da5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "heraclitus-compiler" -version = "1.7.5" +version = "1.7.6" dependencies = [ "capitalize", "colored", diff --git a/Cargo.toml b/Cargo.toml index fba97a2..ecb8ed7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/README.md b/README.md index e2a729a..044c47c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/compiling/failing/logger.rs b/src/compiling/failing/logger.rs index c7754b9..a7e2dec 100644 --- a/src/compiling/failing/logger.rs +++ b/src/compiling/failing/logger.rs @@ -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}")) }