You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: produce valid code when adding constraint to context
This closes#4648.
When adding constraint to a context which is followed by a comment, such
as:
```
foo :: (Monad m) =>
-- | This is a comment
m ()
```
The comment annotation is anchored to the previous token, which is `=>`
in this context. If we add a new constraint in the context, the newly
generated content goes beyond the anchor and, depending on GHC version,
or ghc-exactprint (the reason is not fully understood), the comment is
printed BEFORE the new constraint, leading to invalid syntax, such as
`(Monad m -- | This is a comment , Applicative m =>)`
This commit moves all the comment of the block at the end of the block
using the `followingComments` of `EpAnnComments`.
It seems super adhoc, but actually, consider the following example:
```haskell
bar ::
-- BEFORE
{- yoto -} (Monad m {- yiti -}){- yutu -} => {- yete -} -- Trailing
-- After
m ()
```
Comment `BEFORE` and `yoto` are attached to the previous block. Comment
`yiti` is attached to `Monad m`.
The comments `yiti`, `yutu`, `yete`, `Trailing` and `After` are all
attached to this block and will hence be moved after the block.
However this is not an easy task, all the associated comments should be
moved by the relevant offset.
TODO: do that instead.
0 commit comments