Inconsistent parsing of Haddocks in export lists
Summary
Originally reported in https://github.com/tweag/ormolu/issues/901. The issue is that given this input:
module Beckhoff.ADS
( -- $intro
-- * Connections
ConnectInfo(..)
) where
The comment ends up in two different places:
- As an annotation:
(L
(Anchor
{ <input>:(2,5)-(3,20) }
(UnchangedAnchor))
(EpaComment
(EpaDocCommentNamed
"intro\n * Connections")
{ <input>:2:3 }))
- As a Haddock (
IEDocNamed
):
(L
(SrcSpanAnn (EpAnnNotUsed) { <input>:(2,5)-(3,20) })
(IEDocNamed
(NoExtField)
"intro"))
However, the Haddock version is truncated and does not contain the -- * Connections
part. This, one could argue, is misleading because the -- *
construct (supposed to start a new section) is not recognized in this case, presumably because there is no empty line between the -- $
part and the -- *
part?
Steps to reproduce
Run the parser on the snippet provided above.
Expected behavior
I think there are two ways to resole it:
- Make both the annotation and the Haddock form of the comment match. This is only logical and it would fix the problem in Ormolu.
- Change the parser to recognize
-- *
even when it follows-- $
without a newline between them. This seems to me preferable because it is what users would normally want.
Environment
- GHC version used: Seems to be reproducible with 9.0.2, 9.2.5, 9.4.4.
Optional:
- Operating System: NixOS 23.05 (Stoat)
- System Architecture: x86_64