Don't barf on 'HsSpliceTy'
authorAlec Theriault <alec.theriault@gmail.com>
Mon, 5 Feb 2018 21:45:47 +0000 (13:45 -0800)
committerSean Whitton <spwhitton@spwhitton.name>
Tue, 6 Feb 2018 21:01:18 +0000 (21:01 +0000)
This handles 'HsSpliceTy's by replacing them with what they expand to.
IIUC everything that is happening, 'renameHsSpliceTy' should not be
able to fail for the inputs we feed it from GHC.

This fixes #574.

Gbp-Pq: Name fix-hssplicety.patch

utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs

index 3054e2f976402e5e7a7e7d27d10b59a8d730d203..6ee807e33c9c85b68fc369b5d8005e4b4dfd9694 100644 (file)
@@ -263,10 +263,21 @@ renameType t = case t of
   HsCoreTy a              -> pure (HsCoreTy a)
   HsExplicitListTy  a b   -> HsExplicitListTy  a <$> mapM renameLType b
   HsExplicitTupleTy a b   -> HsExplicitTupleTy a <$> mapM renameLType b
-  HsSpliceTy _ _          -> error "renameType: HsSpliceTy"
+  HsSpliceTy s _          -> renameHsSpliceTy s
   HsWildCardTy a          -> HsWildCardTy <$> renameWildCardInfo a
   HsAppsTy _              -> error "renameType: HsAppsTy"
 
+-- | Rename splices, but _only_ those that turn out to be for types.
+-- I think this is actually safe for our possible inputs:
+--
+--  * the input is from after GHC's renamer, so should have an 'HsSpliced'
+--  * the input is typechecked, and only 'HsSplicedTy' should get through that
+--
+renameHsSpliceTy :: HsSplice Name -> RnM (HsType DocName)
+renameHsSpliceTy (HsSpliced _ (HsSplicedTy t)) = renameType t
+renameHsSpliceTy (HsSpliced _ _) = error "renameHsSpliceTy: not an HsSplicedTy"
+renameHsSpliceTy _ = error "renameHsSpliceTy: not an HsSpliced"
+
 renameLHsQTyVars :: LHsQTyVars Name -> RnM (LHsQTyVars DocName)
 renameLHsQTyVars (HsQTvs { hsq_implicit = _, hsq_explicit = tvs })
   = do { tvs' <- mapM renameLTyVarBndr tvs