From 6def2ea81319f2ecd29b8ae1dc4ef7ae12b76f66 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Fri, 1 Sep 2023 19:17:39 -0500 Subject: [PATCH] Fix LuaJIT number panics in verify mode --- CHANGELOG.md | 4 ++++ src/verify_ast.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b6b5dd2..09d3abf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/verify_ast.rs b/src/verify_ast.rs index 503243bd..374c9b97 100644 --- a/src/verify_ast.rs +++ b/src/verify_ast.rs @@ -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::() { Ok(num) => num, @@ -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();