diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ac6dc18..787edf22 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 ebc73c27..2987879c 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();