@@ -451,9 +451,10 @@ availExportItem is_sig modMap thisMod semMod warnings exportedNames
451
451
, Just f <- [M. lookup n fixMap]
452
452
]
453
453
454
+ extracted <- extractDecl (availName avail) decl
455
+
454
456
return [ ExportDecl {
455
- expItemDecl = restrictTo (fmap fst subs)
456
- (extractDecl declMap (availName avail) decl)
457
+ expItemDecl = restrictTo (fmap fst subs) extracted
457
458
, expItemPats = bundledPatSyns
458
459
, expItemMbDoc = doc
459
460
, expItemSubDocs = subs
@@ -464,17 +465,18 @@ availExportItem is_sig modMap thisMod semMod warnings exportedNames
464
465
]
465
466
466
467
| otherwise =
467
- return [ ExportDecl {
468
- expItemDecl = extractDecl declMap sub decl
469
- , expItemPats = []
470
- , expItemMbDoc = sub_doc
471
- , expItemSubDocs = []
472
- , expItemInstances = []
473
- , expItemFixities = [ (sub, f) | Just f <- [M. lookup sub fixMap] ]
474
- , expItemSpliced = False
475
- }
476
- | (sub, sub_doc) <- subs
477
- ]
468
+ let extractSub (sub, sub_doc) = do
469
+ extracted <- extractDecl sub decl
470
+ pure (ExportDecl {
471
+ expItemDecl = extracted
472
+ , expItemPats = []
473
+ , expItemMbDoc = sub_doc
474
+ , expItemSubDocs = []
475
+ , expItemInstances = []
476
+ , expItemFixities = [ (sub, f) | Just f <- [M. lookup sub fixMap] ]
477
+ , expItemSpliced = False
478
+ })
479
+ in traverse extractSub subs
478
480
479
481
exportedNameSet = mkNameSet exportedNames
480
482
isExported n = elemNameSet n exportedNameSet
@@ -620,9 +622,9 @@ lookupDocs avail warnings docMap argMap =
620
622
-- it might be an individual record selector or a class method. In these
621
623
-- cases we have to extract the required declaration (and somehow cobble
622
624
-- together a type signature for it...).
623
- extractDecl :: DeclMap -> Name -> LHsDecl GhcRn -> LHsDecl GhcRn
624
- extractDecl declMap name decl
625
- | name `elem` getMainDeclBinder (unLoc decl) = decl
625
+ extractDecl :: Name -> LHsDecl GhcRn -> ErrMsgGhc ( LHsDecl GhcRn )
626
+ extractDecl name decl
627
+ | name `elem` getMainDeclBinder (unLoc decl) = pure decl
626
628
| otherwise =
627
629
case unLoc decl of
628
630
TyClD _ d@ ClassDecl {} ->
@@ -645,29 +647,34 @@ extractDecl declMap name decl
645
647
in case (matchesMethod, matchesAssociatedType) of
646
648
([s0], _) -> let (n, tyvar_names) = (tcdName d, tyClDeclTyVars d)
647
649
L pos sig = addClassContext n tyvar_names s0
648
- in L pos (SigD noExt sig)
649
- (_, [L pos fam_decl]) -> L pos (TyClD noExt (FamDecl noExt fam_decl))
650
-
651
- ([] , [] )
652
- | Just (famInstDecl: _) <- M. lookup name declMap
653
- -> extractDecl declMap name famInstDecl
650
+ in pure (L pos (SigD noExt sig))
651
+ (_, [L pos fam_decl]) -> pure (L pos (TyClD noExt (FamDecl noExt fam_decl)))
652
+
653
+ ([] , [] ) -> do
654
+ famInstDeclOpt <- hiDecl name
655
+ case famInstDeclOpt of
656
+ Nothing -> O. pprPanic " extractDecl" (O. text " Failed to find decl for" O. <+> O. ppr name)
657
+ Just famInstDecl -> extractDecl name famInstDecl
654
658
_ -> O. pprPanic " extractDecl" (O. text " Ambiguous decl for" O. <+> O. ppr name O. <+> O. text " in class:"
655
659
O. $$ O. nest 4 (O. ppr d)
656
660
O. $$ O. text " Matches:"
657
661
O. $$ O. nest 4 (O. ppr matchesMethod O. <+> O. ppr matchesAssociatedType))
658
- TyClD _ d@ DataDecl {} ->
662
+ TyClD _ d@ DataDecl {} -> pure $
659
663
let (n, tyvar_tys) = (tcdName d, lHsQTyVarsToTypes (tyClDeclTyVars d))
660
664
in if isDataConName name
661
665
then SigD noExt <$> extractPatternSyn name n tyvar_tys (dd_cons (tcdDataDefn d))
662
666
else SigD noExt <$> extractRecSel name n tyvar_tys (dd_cons (tcdDataDefn d))
663
667
TyClD _ FamDecl {}
664
668
| isValName name
665
- , Just (famInst: _) <- M. lookup name declMap
666
- -> extractDecl declMap name famInst
669
+ -> do
670
+ famInstOpt <- hiDecl name
671
+ case famInstOpt of
672
+ Nothing -> O. pprPanic " extractDecl" (O. text " Failed to find decl for" O. <+> O. ppr name)
673
+ Just famInst -> extractDecl name famInst
667
674
InstD _ (DataFamInstD _ (DataFamInstDecl (HsIB { hsib_body =
668
675
FamEqn { feqn_tycon = L _ n
669
676
, feqn_pats = tys
670
- , feqn_rhs = defn }}))) ->
677
+ , feqn_rhs = defn }}))) -> pure $
671
678
if isDataConName name
672
679
then SigD noExt <$> extractPatternSyn name n tys (dd_cons defn)
673
680
else SigD noExt <$> extractRecSel name n tys (dd_cons defn)
@@ -680,7 +687,7 @@ extractDecl declMap name decl
680
687
, name `elem` map unLoc (concatMap (getConNames . unLoc) (dd_cons dd))
681
688
]
682
689
in case matches of
683
- [d0] -> extractDecl declMap name (noLoc (InstD noExt (DataFamInstD noExt d0)))
690
+ [d0] -> extractDecl name (noLoc (InstD noExt (DataFamInstD noExt d0)))
684
691
_ -> error " internal: extractDecl (ClsInstD)"
685
692
| otherwise ->
686
693
let matches = [ d' | L _ d'@ (DataFamInstDecl (HsIB { hsib_body = d }))
@@ -692,7 +699,7 @@ extractDecl declMap name decl
692
699
, extFieldOcc n == name
693
700
]
694
701
in case matches of
695
- [d0] -> extractDecl declMap name (noLoc . InstD noExt $ DataFamInstD noExt d0)
702
+ [d0] -> extractDecl name (noLoc . InstD noExt $ DataFamInstD noExt d0)
696
703
_ -> error " internal: extractDecl (ClsInstD)"
697
704
x -> O. pprPanic " extractDecl" (O. ppr x)
698
705
0 commit comments