This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Description
These testcases from GHC have an unusual format:
-
haddockA006.hs:
{-^ wealwwwwwwwwwwww
-}
main = return ()
-
haddockA013.hs:
module ShouldCompile where
-- ^ bla
main=undefined
-- ^ vkfja
hej=main
-- ^ ieasdkjahsdkjashd
x = hej
-- ^ eroiewuroieuwr
y = undefined
Both cases have -- ^-style docstrings above the first declaration they could refer to.
Haddock doesn't complain though and produces

and

The misplaced docstrings are simply attached to the topmost declaration.
This IMO flawed attachment happens here:
go prev docs ((dL->L _ (DocD _ (DocCommentPrev str))) : ds) =
go prev (str:docs) ds
This code doesn't check whether prev, the closest declaration above the docstring, is Nothing. I think it should.
In any case this would be rather late stage to catch misformatted docs. Maybe we can make the parser at least output a warning?