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

Commit 60e10eb

Browse files
RyanGlScottalexbiehl
authored andcommitted
Fix #548 by rendering datatype kinds more carefully (#702)
1 parent deddced commit 60e10eb

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
@@ -164,7 +164,7 @@ synifyTyCon _coax tc
164164
-- algebraic data nor newtype:
165165
, dd_ctxt = noLoc []
166166
, dd_cType = Nothing
167-
, dd_kindSig = Just (synifyKindSig (tyConKind tc))
167+
, dd_kindSig = synifyDataTyConReturnKind tc
168168
-- we have their kind accurately:
169169
, dd_cons = [] -- No constructors
170170
, dd_derivs = noLoc [] }
@@ -219,7 +219,7 @@ synifyTyCon coax tc
219219
-- CoAxioms, not their TyCons
220220
_ -> synifyName tc
221221
tyvars = synifyTyVars (tyConVisibleTyVars tc)
222-
kindSig = Just (tyConKind tc)
222+
kindSig = synifyDataTyConReturnKind tc
223223
-- The data constructors.
224224
--
225225
-- Any data-constructors not exported from the module that *defines* the
@@ -244,7 +244,7 @@ synifyTyCon coax tc
244244
defn = HsDataDefn { dd_ND = alg_nd
245245
, dd_ctxt = alg_ctx
246246
, dd_cType = Nothing
247-
, dd_kindSig = fmap synifyKindSig kindSig
247+
, dd_kindSig = kindSig
248248
, dd_cons = cons
249249
, dd_derivs = alg_deriv }
250250
in case lefts consRaw of
@@ -254,6 +254,27 @@ synifyTyCon coax tc
254254
, tcdDataCusk = False, tcdFVs = placeHolderNamesTc }
255255
dataConErrs -> Left $ unlines dataConErrs
256256

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

0 commit comments

Comments
 (0)