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:
addAnnotationsForPretty
inserts a leading space forHsVar
s (orRdrName
s, I haven't dug in). This is the wrong thing to do in the case of aBodyStmt
, which will break thedo
block's layout.Consider this:
and we want to append a new
noLoc $ BodyStmt _ (noLoc $ HsVar _ (noLoc $ Unqual "b") _ _
forb
into the do block. After making new source spans for the noLocs, wen can calladdAnnotationsForPretty
, on theBodyStmt
above, but printing this is:which is a parse error :(