Opened 13 months ago

Last modified 12 months ago

#15760 new bug

Preserve parens in TH

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 8.6.1
Keywords: Cc: int-e
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #15815, #15824 Differential Rev(s):
Wiki Page:

Description

Template Haskell supports parentheses in its AST. So does GHC. Yet GHC casually discards parentheses when desugaring TH quotes. We should preserve them.

I was originally thinking that this could get rid of Note [Adding parens for splices] in Convert, but that processing would still be necessary if we are converting TH AST that did not come from a quote. Actually, it gets worse with this change, because we don't want to add redundant parens.

Still, I think preserving parens is the right thing to do here. It also makes it possible for a client to give special meaning to, say, nested parens: Perhaps process [| f x |] and process [| f ((x)) |] will behave differently. (Idiom brackets, anyone?)

Change History (4)

comment:1 Changed 13 months ago by RyanGlScott

That sounds like a reasonable enough desire. Where are you applying this fix? In DsMeta? If so, please make sure that the functions in Convert don't accidentally add extraneous parentheses (I've tried quite hard to ensure that Convert only adds required parentheses if they're missing, but it's quite possible that I've missed a case).

comment:2 Changed 13 months ago by RyanGlScott

See #15815 for a notable example of a bug that this issue causes.

comment:3 Changed 13 months ago by int-e

Cc: int-e added

comment:4 Changed 12 months ago by int-index

Note: See TracTickets for help on using tickets.