Skip to content

Commit

Permalink
Merge pull request #50 from Ph0enixKM/panic-when-out-of-bounds
Browse files Browse the repository at this point in the history
Remove panic when error happens out of bounds of file
  • Loading branch information
Ph0enixKM committed Jul 6, 2024
2 parents ec44c83 + fde4e17 commit f8a42a8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 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.5.9"
version = "1.6.0"
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.6.0
### Fix:
- Heraclitus no longer panics when error happens out of bounds of file

## Version 1.5.9
### Fix:
- Escaping escape key now treats it as a character
Expand Down
24 changes: 22 additions & 2 deletions src/compiling/failing/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl Logger {
let (row, col, len) = self.get_row_col_len();
let max_pad = self.get_max_pad_size(code.len());
let index = index as i32 + offset as i32;
if code.get(index as usize).is_none() {
return String::new();
}
let row = row as i32 + offset as i32;
let code = code[index as usize].clone();
let line = format!("{row}").pad_to_width(max_pad);
Expand Down Expand Up @@ -208,7 +211,7 @@ mod test {

use crate::prelude::{PositionInfo, MessageType};
#[allow(unused_variables)]

#[test]
fn test_displayer() {
let code = vec![
Expand All @@ -229,4 +232,21 @@ mod test {
.path()
.snippet(Some(code));
}
}

#[test]
fn test_end_of_line_displayer() {
let code = vec![
"hello"
].join("\n");
// Uncomment to see the error message
sleep(Duration::from_secs(1));
let trace = [
PositionInfo::at_pos(Some("/path/to/foo".to_string()), (2, 6), 1)
];
super::Logger::new(MessageType::Error, &trace)
.header(MessageType::Error)
.text(Some(format!("Cannot call function \"foobar\" on a number")))
.path()
.snippet(Some(code));
}
}

0 comments on commit f8a42a8

Please sign in to comment.