aboutsummaryrefslogtreecommitdiff
path: root/haddock-api/src/Haddock/Utils.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-10-24 10:38:55 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2020-10-30 04:53:05 -0400
commit3cce1bdee8c61bb6daa089059e12435178f50770 (patch)
tree32cb09fe0afa9753bf82fd90bd7016336439fc7b /haddock-api/src/Haddock/Utils.hs
parent87a9f86d1ad7de67ff011311905ecf76578b26e9 (diff)
Adapt to HsConDecl{H98,GADT}Details split
Needed for GHC#18844.
Diffstat (limited to 'haddock-api/src/Haddock/Utils.hs')
-rw-r--r--haddock-api/src/Haddock/Utils.hs28
1 files changed, 20 insertions, 8 deletions
diff --git a/haddock-api/src/Haddock/Utils.hs b/haddock-api/src/Haddock/Utils.hs
index 33fbd000..1177fb18 100644
--- a/haddock-api/src/Haddock/Utils.hs
+++ b/haddock-api/src/Haddock/Utils.hs
@@ -187,21 +187,33 @@ restrictCons :: [Name] -> [LConDecl GhcRn] -> [LConDecl GhcRn]
restrictCons names decls = [ L p d | L p (Just d) <- map (fmap keep) decls ]
where
keep d | any (\n -> n `elem` names) (map unLoc $ getConNames d) =
- case con_args d of
- PrefixCon _ -> Just d
- RecCon fields
- | all field_avail (unL fields) -> Just d
- | otherwise -> Just (d { con_args = PrefixCon (field_types (map unL (unL fields))) })
+ case d of
+ ConDeclH98 { con_args = args } -> restrict_h98_args args
+ ConDeclGADT { con_g_args = args } -> restrict_gadt_args args
+ where
+ restrict_h98_args :: HsConDeclH98Details GhcRn -> Maybe (ConDecl GhcRn)
+ restrict_h98_args (PrefixCon _) = Just d
+ restrict_h98_args (RecCon (L _ fields))
+ | all field_avail fields = Just d
+ | otherwise = Just (d { con_args = PrefixCon (field_types fields) })
-- if we have *all* the field names available, then
-- keep the record declaration. Otherwise degrade to
-- a constructor declaration. This isn't quite right, but
-- it's the best we can do.
- InfixCon _ _ -> Just d
- where
+
+ restrict_h98_args (InfixCon _ _) = Just d
+
+ restrict_gadt_args :: HsConDeclGADTDetails GhcRn -> Maybe (ConDecl GhcRn)
+ restrict_gadt_args (PrefixConGADT _) = Just d
+ restrict_gadt_args (RecConGADT (L _ fields))
+ | all field_avail fields = Just d
+ | otherwise = Just (d { con_g_args = PrefixConGADT (field_types fields) })
+ -- see the comments for the RecCon case of `restrict_h98_args` above
+
field_avail :: LConDeclField GhcRn -> Bool
field_avail (L _ (ConDeclField _ fs _ _))
= all (\f -> extFieldOcc (unLoc f) `elem` names) fs
- field_types flds = [ hsUnrestricted t | ConDeclField _ _ t _ <- flds ]
+ field_types flds = [ hsUnrestricted t | L _ (ConDeclField _ _ t _) <- flds ]
keep _ = Nothing