alanz / ghc-exactprint

GHC version of haskell-src-exts exactPrint
BSD 3-Clause "New" or "Revised" License
70 stars 32 forks source link

addAnnotationsForPretty doesn't play nicely with do blocks #80

Open isovector opened 5 years ago

isovector commented 5 years ago

addAnnotationsForPretty inserts a leading space for HsVars (or RdrNames, I haven't dug in). This is the wrong thing to do in the case of a BodyStmt, which will break the do block's layout.

Consider this:

foo = do
  a

and we want to append a new noLoc $ BodyStmt _ (noLoc $ HsVar _ (noLoc $ Unqual "b") _ _ for b into the do block. After making new source spans for the noLocs, wen can call addAnnotationsForPretty, on the BodyStmt above, but printing this is:

foo = do
  a
   b

which is a parse error :(