diff options
author | Luke Lau <luke_lau@icloud.com> | 2020-05-26 18:42:12 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-04 04:36:41 -0400 |
commit | 2bd3929ad1b06b01c1d22d513902507eefadc131 (patch) | |
tree | c313f6533d672b0b1dcdbe0e353a7d2182f38faf /compiler | |
parent | 1b975aedb1b74b8694d14ba8fdc5955497f8f31c (diff) | |
download | haskell-2bd3929ad1b06b01c1d22d513902507eefadc131.tar.gz |
Fix documentation on type families not being extracted
It looks like the location of the Names used for CoAxioms on type
families are now located at their type constructors. Previously, Docs.hs
thought the Names were located in the RHS, so the RealSrcSpan in the
instanceMap and getInstLoc didn't match up. Fixes #18241
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/HsToCore/Docs.hs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/compiler/GHC/HsToCore/Docs.hs b/compiler/GHC/HsToCore/Docs.hs index 1aee1fbd68..0f6d8ba9e4 100644 --- a/compiler/GHC/HsToCore/Docs.hs +++ b/compiler/GHC/HsToCore/Docs.hs @@ -97,13 +97,7 @@ mkMaps instances decls = instanceMap = M.fromList [(l, n) | n <- instances, RealSrcSpan l _ <- [getSrcSpan n] ] names :: RealSrcSpan -> HsDecl GhcRn -> [Name] - names l (InstD _ d) = maybeToList $ -- See Note [1]. - case d of - TyFamInstD _ _ -> M.lookup l instanceMap - -- The CoAx's loc is the whole line, but only - -- for TFs - _ -> lookupSrcSpan (getInstLoc d) instanceMap - + names _ (InstD _ d) = maybeToList $ lookupSrcSpan (getInstLoc d) instanceMap names l (DerivD {}) = maybeToList (M.lookup l instanceMap) -- See Note [1]. names _ decl = getMainDeclBinder decl @@ -145,14 +139,16 @@ sigNameNoLoc _ = [] getInstLoc :: InstDecl (GhcPass p) -> SrcSpan getInstLoc = \case ClsInstD _ (ClsInstDecl { cid_poly_ty = ty }) -> getLoc (hsSigType ty) + -- The Names of data and type family instances have their SrcSpan's attached + -- to the *type constructor*. For example, the Name "D:R:Foo:Int" would have + -- its SrcSpan attached here: + -- type family Foo a + -- type instance Foo Int = Bool + -- ^^^ DataFamInstD _ (DataFamInstDecl { dfid_eqn = HsIB { hsib_body = FamEqn { feqn_tycon = L l _ }}}) -> l TyFamInstD _ (TyFamInstDecl - -- Since CoAxioms' Names refer to the whole line for type family instances - -- in particular, we need to dig a bit deeper to pull out the entire - -- equation. This does not happen for data family instances, for some - -- reason. - { tfid_eqn = HsIB { hsib_body = FamEqn { feqn_rhs = L l _ }}}) -> l + { tfid_eqn = HsIB { hsib_body = FamEqn { feqn_tycon = L l _ }}}) -> l -- | Get all subordinate declarations inside a declaration, and their docs. -- A subordinate declaration is something like the associate type or data |