tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
956 stars 83 forks source link

Fix formatting of `SCC` pragmas in `do` blocks #926

Closed amesgen closed 2 years ago

amesgen commented 2 years ago

Closes #925

This fix (re/ab)uses the s :: BracketStyle argument to p_hsExpr' in order to decide whether we are in a do expression: even though this particular case has nothing to do with brackets, it points to the same underlying problem (some stuff has to be indented only in do blocks). This could be potentially confusing for future readers of this code, but the diff is really small, so the effect is not huge in any case.

A slightly more principled fix could look like this: Introduce

data InDoBlock = InDoBlock | NotInDoBlock

and change p_hsExpr''s signature to

p_hsExpr' :: InDoBlock -> HsExpr GhcPs -> R ()

as well as provide a function InDoBlock -> BracketStyle.