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

Strange results with "-- ^"-docstrings above the first declaration #1059

@sjakobi

Description

@sjakobi

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

image

and

image

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions