From 5c3d229d113e5493472b9eb0a3b9f8f8d8ad4ab6 Mon Sep 17 00:00:00 2001 From: mao <118530756+maoxor@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:54:15 +0100 Subject: [PATCH] Fix --verify false positive on nested parentheses The verifier removed a single level of parentheses, while the formatter can collapse ((x)) into x or (x), so any doubled parentheses were reported as a possible change in the AST. --- CHANGELOG.md | 4 ++++ src/verify_ast.rs | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac6dc18d..787edf22d 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 `--verify` reporting that the output AST may be different when the input has nested parentheses such as `((x))` + ## [2.6.0] - 2026-10-10 ### Added diff --git a/src/verify_ast.rs b/src/verify_ast.rs index ebc73c27e..2987879c2 100644 --- a/src/verify_ast.rs +++ b/src/verify_ast.rs @@ -31,7 +31,8 @@ impl AstVerifier { fn remove_parentheses(expression: Expression) -> Expression { match expression { - Expression::Parentheses { expression, .. } => *expression, + // Remove every level, as the formatter can collapse `((x))` into `x` + Expression::Parentheses { expression, .. } => remove_parentheses(*expression), _ => expression, } } @@ -284,6 +285,15 @@ mod tests { assert!(ast_verifier.compare(input_ast, output_ast)); } + #[test] + fn test_equivalent_removed_nested_parentheses() { + let input_ast = full_moon::parse("local x = a and ((b >= 1 and b <= 2)) and c").unwrap(); + let output_ast = full_moon::parse("local x = a and (b >= 1 and b <= 2) and c").unwrap(); + + let mut ast_verifier = AstVerifier::new(); + assert!(ast_verifier.compare(input_ast, output_ast)); + } + #[test] fn test_different_hex_numbers() { let input_ast = full_moon::parse("local x = 0xFFAA").unwrap();