Commit 69714306 authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari

Allow putting Haddocks on derived instances

Currently, one can document top-level instance declarations, but derived
instances (both those in `deriving` clauses and standalone `deriving`
instances) do not enjoy the same privilege. This makes the necessary
changes to the parser to enable attaching Haddock comments for derived
instances.

Updates haddock submodule.

Fixes #11768.

Test Plan: ./validate

Reviewers: hvr, bgamari, austin

Reviewed By: austin

Subscribers: thomie, mpickering

Differential Revision: https://phabricator.haskell.org/D2175

GHC Trac Issues: #11768
parent b8e25651
......@@ -1727,9 +1727,9 @@ inst_type :: { LHsSigType RdrName }
: sigtype { mkLHsSigType $1 }
deriv_types :: { [LHsSigType RdrName] }
: type { [mkLHsSigType $1] }
: typedoc { [mkLHsSigType $1] }
| type ',' deriv_types {% addAnnotation (gl $1) AnnComma (gl $2)
| typedoc ',' deriv_types {% addAnnotation (gl $1) AnnComma (gl $2)
>> return (mkLHsSigType $1 : $3) }
comma_types0 :: { [LHsType RdrName] } -- Zero or more: ty,ty,ty
......@@ -1936,10 +1936,9 @@ fielddecl :: { LConDeclField RdrName }
-- know the rightmost extremity of the 'deriving' clause
deriving :: { Located (HsDeriving RdrName) }
: {- empty -} { noLoc Nothing }
| 'deriving' qtycon {% let { L tv_loc tv = $2
; full_loc = comb2 $1 $> }
| 'deriving' qtycondoc {% let { full_loc = comb2 $1 $> }
in ams (L full_loc $ Just $ L full_loc $
[mkLHsSigType (L tv_loc (HsTyVar $2))])
[mkLHsSigType $2])
[mj AnnDeriving $1] }
| 'deriving' '(' ')' {% let { full_loc = comb2 $1 $> }
......@@ -2896,6 +2895,10 @@ qtycon :: { Located RdrName } -- Qualified or unqualified
: QCONID { sL1 $1 $! mkQual tcClsName (getQCONID $1) }
| tycon { $1 }
qtycondoc :: { LHsType RdrName } -- Qualified or unqualified
: qtycon { sL1 $1 (HsTyVar $1) }
| qtycon docprev { sLL $1 $> (HsDocTy (sL1 $1 (HsTyVar $1)) $2) }
tycon :: { Located RdrName } -- Unqualified
: CONID { sL1 $1 $! mkUnqual tcClsName (getCONID $1) }
......
{-# LANGUAGE StandaloneDeriving #-}
module T11768 where
data Foo = Foo
deriving Eq -- ^ Documenting a single type
data Bar = Bar
deriving ( Eq -- ^ Documenting one of multiple types
, Ord
)
-- | Documenting a standalone deriving instance
deriving instance Read Bar
==================== Parser ====================
module T11768 where
data Foo
= Foo
deriving (Eq Documenting a single type)
data Bar
= Bar
deriving (Eq Documenting one of multiple types, Ord)
<document comment>
deriving instance Read Bar
......@@ -46,3 +46,4 @@ test('haddockA032', normal, compile, ['-haddock -ddump-parsed'])
test('haddockA033', normal, compile, ['-haddock -ddump-parsed'])
test('haddockA034', normal, compile, ['-haddock -ddump-parsed'])
test('T10398', normal, compile, ['-haddock -ddump-parsed'])
test('T11768', normal, compile, ['-haddock -ddump-parsed'])
Subproject commit 9760ee9efe22f0256d626bc567a7adfc754e9066
Subproject commit d7ef90898c6d8ddeae23caf0f9fb68c25537dcd0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment