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

Commit 3743d08

Browse files
RyanGlScottalexbiehl
authored andcommitted
Fix #548 by rendering datatype kinds more carefully (#702)
1 parent e5fe985 commit 3743d08

File tree

4 files changed

+629
-3
lines changed

4 files changed

+629
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ TAGS
2525
.cabal-sandbox
2626
.ghc.environment.*
2727
cabal.sandbox.config
28+
cabal.project.local
29+
cabal.project.local~
2830

2931
.stack-work/

haddock-api/src/Haddock/Convert.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ synifyTyCon _coax tc
155155
-- algebraic data nor newtype:
156156
, dd_ctxt = noLoc []
157157
, dd_cType = Nothing
158-
, dd_kindSig = Just (synifyKindSig (tyConKind tc))
158+
, dd_kindSig = synifyDataTyConReturnKind tc
159159
-- we have their kind accurately:
160160
, dd_cons = [] -- No constructors
161161
, dd_derivs = noLoc [] }
@@ -210,7 +210,7 @@ synifyTyCon coax tc
210210
-- CoAxioms, not their TyCons
211211
_ -> synifyName tc
212212
tyvars = synifyTyVars (tyConTyVars tc)
213-
kindSig = Just (tyConKind tc)
213+
kindSig = synifyDataTyConReturnKind tc
214214
-- The data constructors.
215215
--
216216
-- Any data-constructors not exported from the module that *defines* the
@@ -235,7 +235,7 @@ synifyTyCon coax tc
235235
defn = HsDataDefn { dd_ND = alg_nd
236236
, dd_ctxt = alg_ctx
237237
, dd_cType = Nothing
238-
, dd_kindSig = fmap synifyKindSig kindSig
238+
, dd_kindSig = kindSig
239239
, dd_cons = cons
240240
, dd_derivs = alg_deriv }
241241
in case lefts consRaw of
@@ -245,6 +245,27 @@ synifyTyCon coax tc
245245
, tcdDataCusk = False, tcdFVs = placeHolderNamesTc }
246246
dataConErrs -> Left $ unlines dataConErrs
247247

248+
-- In this module, every TyCon being considered has come from an interface
249+
-- file. This means that when considering a data type constructor such as:
250+
--
251+
-- data Foo (w :: *) (m :: * -> *) (a :: *)
252+
--
253+
-- Then its tyConKind will be (* -> (* -> *) -> * -> *). But beware! We are
254+
-- also rendering the type variables of Foo, so if we synify the tyConKind of
255+
-- Foo in full, we will end up displaying this in Haddock:
256+
--
257+
-- data Foo (w :: *) (m :: * -> *) (a :: *)
258+
-- :: * -> (* -> *) -> * -> *
259+
--
260+
-- Which is entirely wrong (#548). We only want to display the *return* kind,
261+
-- which this function obtains.
262+
synifyDataTyConReturnKind :: TyCon -> Maybe (LHsKind Name)
263+
synifyDataTyConReturnKind tc
264+
= case splitFunTys (tyConKind tc) of
265+
(_, ret_kind)
266+
| isLiftedTypeKind ret_kind -> Nothing -- Don't bother displaying :: *
267+
| otherwise -> Just (synifyKindSig ret_kind)
268+
248269
synifyInjectivityAnn :: Maybe Name -> [TyVar] -> Injectivity
249270
-> Maybe (LInjectivityAnn Name)
250271
synifyInjectivityAnn Nothing _ _ = Nothing

0 commit comments

Comments
 (0)