Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: 55326fa0 by Alan Zimmerman at 2026-08-28T06:08:03-04:00 EPA: Some Haddock processing tweaks These changes to the Haddock postprocessing should not change behaviour, but just bring it more closely in line with the original, changed at 44309cd377f And add some haddock exactprint tests to show they work. - - - - - 4 changed files: - compiler/GHC/Parser/PostProcess/Haddock.hs - + testsuite/tests/printer/Haddock1.hs - testsuite/tests/printer/Makefile - testsuite/tests/printer/all.T Changes: ===================================== compiler/GHC/Parser/PostProcess/Haddock.hs ===================================== @@ -265,12 +265,14 @@ instance HasHaddock (Located (HsModule GhcPs)) where -- ) where -- -- Only do this when the export list exists. - let (_, close_paren, _) = am_exports mod_anns + let + (open_paren, close_paren, _) = am_exports mod_anns + l_exports = combineSrcSpans (getEpTokenSrcSpan open_paren) (getEpTokenSrcSpan close_paren) hsmodExports' <- traverse @Maybe (\exports -> - extendHdkA (getEpTokenSrcSpan close_paren) $ do + extendHdkA l_exports $ do exports' <- addHaddockInterleaveItems EpNoLayout mkDocIE exports - registerEpTokenHdkA close_paren -- ) position, not end-of-last-item + registerEpTokenHdkA close_paren -- Do not consume comments after the closing parenthesis pure exports') (hsmodExports mod) ===================================== testsuite/tests/printer/Haddock1.hs ===================================== @@ -0,0 +1,36 @@ +{-# OPTIONS_GHC -fno-warn-redundant-constraints -haddock #-} +-- | Haddock comment, +-- coming before the module +module Haddock1 ( + + -- | This is some inline documentation in the export list + -- + -- > a code block using bird-tracks + -- > each line must begin with > (which isn't significant unless it + -- > is at the beginning of the line). + f + + {-| nested-style doc comments -} + , g + + -- * A section + -- and without an intervening comma: + -- ** A subsection + ) where + +-- | Haddock before imports +import Data.List + +-- | Haddock before decl +f = undefined +g = undefined + +-- | This comment applies to the /following/ declaration +-- and it continues until the next non-comment line +data T a b + = A Int (Maybe Float) -- ^ This comment describes the 'A' constructor + | -- | This comment describes the 'B' constructor + B (T a b, T Int Float) -- ^ abcd + +-- | An abstract data declaration +data T2 a b = T2 a b ===================================== testsuite/tests/printer/Makefile ===================================== @@ -932,3 +932,8 @@ PprModifiers: PprQualifiedStrings: $(CHECK_PPR) $(LIBDIR) PprQualifiedStrings.hs $(CHECK_EXACT) $(LIBDIR) PprQualifiedStrings.hs + +.PHONY: Haddock1 +Haddock1: + # $(CHECK_PPR) $(LIBDIR) Haddock1.hs + $(CHECK_EXACT) $(LIBDIR) Haddock1.hs ===================================== testsuite/tests/printer/all.T ===================================== @@ -223,3 +223,4 @@ test('TestLevelImports', [ignore_stderr, req_ppr_deps], makefile_test, ['TestLev test('TestNamedDefaults', [ignore_stderr, req_ppr_deps], makefile_test, ['TestNamedDefaults']) test('PprModifiers', [ignore_stderr,req_ppr_deps], makefile_test, ['PprModifiers']) test('PprQualifiedStrings', [ignore_stderr,req_ppr_deps], makefile_test, ['PprQualifiedStrings']) +test('Haddock1', [ignore_stderr,req_ppr_deps], makefile_test, ['Haddock1']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55326fa0c05c4fb21c6cea9934b19efb... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/55326fa0c05c4fb21c6cea9934b19efb... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help