From e5bd27b5edf533054513871dc475a54a8b1bee23 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Mon, 24 Feb 2014 22:01:11 +0000 Subject: Change rendering of duplicate record field docs See Haddock Trac #195. We now change this behaviour to only rendering the documentation attached to the first instance of a duplicate field. Perhaps we could improve this by rendering the first instance that has documentation attached to it but for now, we'll stick with this. --- doc/haddock.xml | 23 ++++++ html-test/ref/Bug195.html | 179 ++++++++++++++++++++++++++++++++++++++++ html-test/src/Bug195.hs | 11 +++ src/Haddock/Interface/Create.hs | 3 +- 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 html-test/ref/Bug195.html create mode 100644 html-test/src/Bug195.hs diff --git a/doc/haddock.xml b/doc/haddock.xml index bec8067f..5bc27aca 100644 --- a/doc/haddock.xml +++ b/doc/haddock.xml @@ -1218,6 +1218,29 @@ data R a b = Haddock - for example doc comments can appear before or after the comma in separated lists such as the list of record fields above. + + In case that more than one constructor exports a field + with the same name, the documentation attached to the first + occurence of the field will be used, even if a comment is not + present. + + + +data T a = A { someField :: a -- ^ Doc for someField of A + } + | B { someField :: a -- ^ Doc for someField of B + } + + + In the above example, all occurences of + someField in the documentation are going to + be documented with Doc for someField of A. + Note that Haddock versions 2.14.0 and before would join up + documentation of each field and render the result. The reason + for this seemingly weird behaviour is the fact that + someField is actually the same (partial) + function. +
diff --git a/html-test/ref/Bug195.html b/html-test/ref/Bug195.html new file mode 100644 index 00000000..9ab7c3b0 --- /dev/null +++ b/html-test/ref/Bug195.html @@ -0,0 +1,179 @@ + +Bug195
Safe HaskellSafe-Inferred

Bug195

Documentation

data T

Constructors

A 

Fields

someField :: ()

Doc for someField of A

someOtherField :: ()

Doc for someOtherField of A

B 

Fields

someField :: ()

Doc for someField of A

someOtherField :: ()

Doc for someOtherField of A

C 

Fields

someField :: ()

Doc for someField of A

someOtherField :: ()

Doc for someOtherField of A

diff --git a/html-test/src/Bug195.hs b/html-test/src/Bug195.hs new file mode 100644 index 00000000..14440e8d --- /dev/null +++ b/html-test/src/Bug195.hs @@ -0,0 +1,11 @@ +module Bug195 where + +data T = A { someField :: () -- ^ Doc for someField of A + , someOtherField :: () -- ^ Doc for someOtherField of A + } + | B { someField :: () -- ^ Doc for someField of B + , someOtherField :: () -- ^ Doc for someOtherField of B + } + | C { someField :: () -- ^ Doc for someField of C + , someOtherField :: () -- ^ Doc for someOtherField of C + } diff --git a/src/Haddock/Interface/Create.hs b/src/Haddock/Interface/Create.hs index cf5a3451..f3658a12 100644 --- a/src/Haddock/Interface/Create.hs +++ b/src/Haddock/Interface/Create.hs @@ -31,6 +31,7 @@ import Data.Ord import Control.Applicative import Control.DeepSeq import Control.Monad +import Data.Function (on) import qualified Data.Foldable as F import qualified Data.Traversable as T @@ -255,7 +256,7 @@ mkMaps :: DynFlags -> ErrMsgM Maps mkMaps dflags gre instances decls = do (a, b, c, d) <- unzip4 <$> mapM mappings decls - return (f a, f b, f c, f d, instanceMap) + return (f $ map (nubBy ((==) `on` fst)) a , f b, f c, f d, instanceMap) where f :: (Ord a, Monoid b) => [[(a, b)]] -> Map a b f = M.fromListWith (<>) . concat -- cgit v1.2.3