Skip to content

Fix --verify false positive on nested parentheses - #1181

Open
maoxor wants to merge 1 commit into
JohnnyMorganz:mainfrom
maoxor:fix-verify-nested-parentheses
Open

maoxor wants to merge 1 commit into
JohnnyMorganz:mainfrom
maoxor:fix-verify-nested-parentheses

Conversation

@maoxor

@maoxor maoxor commented Oct 29, 2026

Copy link
Copy Markdown

With --verify, any expression wrapped in two pairs of parentheses is reported as a possible change:

$ echo 'local x = a and ((b >= 1 and b <= 2)) and c' | stylua --verify -
error: could not format from stdin: failed to format from stdin: INTERNAL WARNING: Output AST may be different to input AST. Code correctness may have changed. Please examine the formatting diff and report any issues at https://github.com/johnnymorganz/stylua/issues

The formatter only drops the redundant pair, which is fine, but remove_parentheses in the verifier strips a single level, so the input still has (b >= 1 and b <= 2) where the output has b >= 1 and b <= 2. It now strips every level.

I found it on awesome's spec/awful/prompt_spec.lua ((byte and ((byte >= 194 and byte <= 244)) and ...)). The new test_equivalent_removed_nested_parentheses fails without the change. cargo test passes with the default features, --all-features, --no-default-features, --features luau and --features lua54; clippy (--all-features -D warnings) and cargo fmt --check are clean. A release build with --verify over about 6,000 Lua/Luau files no longer reports any AST difference. The two remaining errors there are the hexadecimal float panic (#1180) and the local -- comment case I added to #1176.

This touches the Unreleased section of the changelog like #1180, so whichever is merged second may need a trivial rebase.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant