Skip to content

Pretty: drop inner parens when CUnary applies to CUnary#110

Open
jkoppel wants to merge 1 commit into
visq:masterfrom
jkoppel:pretty-printer-cosmetic
Open

Pretty: drop inner parens when CUnary applies to CUnary#110
jkoppel wants to merge 1 commit into
visq:masterfrom
jkoppel:pretty-printer-cosmetic

Conversation

@jkoppel
Copy link
Copy Markdown

@jkoppel jkoppel commented May 13, 2026

!!x currently prints as ! (!x). The existing inline comment in Pretty.hs

prettyPrec p (CUnary op expr@(CUnary _ _ _) _) =
    --                             parens aren't necessary, but look nicer imho
    parenPrec p 25 $ pretty op <+> parens (prettyPrec 25 expr)

— already says the parens are stylistic. This drops them: !!x stays !!x. Both forms parse to the same AST, so this is purely about source text; happy to close if you prefer the current output.

(Split from #109, which is the real AST-round-trip bug.)

Original commit by @dvekeman.

`!!x` currently prints as `! (!x)`. The existing inline comment —

    -- parens aren't necessary, but look nicer imho

— already acknowledges this is stylistic. Both forms parse to the
same AST.

Originally authored by @dvekeman in 2016 on the downstream
`jkoppel/language-c` fork.
@jkoppel jkoppel force-pushed the pretty-printer-cosmetic branch from c2d3e39 to 95302b4 Compare May 13, 2026 22:32
@jkoppel jkoppel changed the title Pretty: two source-text tweaks from a downstream fork Pretty: drop inner parens when CUnary applies to CUnary May 13, 2026
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.

2 participants