Skip to content

Commit

Permalink
Fix LuaJIT number panics in verify mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Sep 2, 2023
1 parent fdf9f0c commit 6def2ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixed LuaJIT suffixes `LL`/`ULL` causing a panic when running in `--verify` mode

## [0.18.1] - 2023-07-15

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions src/verify_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ impl VisitorMut for AstVerifier {
// Luau: cleanse number of any digit separators
#[cfg(feature = "luau")]
let text = text.replace('_', "");
// LuaJIT (Lua52): remove suffixes
#[cfg(feature = "lua52")]
let text = text
.trim_end_matches("ULL")
.trim_end_matches("LL")
.to_string();

let number = match text.as_str().parse::<f64>() {
Ok(num) => num,
Expand Down Expand Up @@ -305,6 +311,16 @@ mod tests {
assert!(!ast_verifier.compare(input_ast, output_ast));
}

#[test]
#[cfg(feature = "lua52")]
fn test_equivalent_luajit_numbers() {
let input_ast = full_moon::parse("local x = 2 ^ 63LL").unwrap();
let output_ast = full_moon::parse("local x = 2 ^ 63").unwrap();

let mut ast_verifier = AstVerifier::new();
assert!(ast_verifier.compare(input_ast, output_ast));
}

#[test]
fn test_equivalent_table_separators() {
let input_ast = full_moon::parse("local x = {'a'; 'b'; 'c';}").unwrap();
Expand Down

0 comments on commit 6def2ea

Please sign in to comment.