hsinspect 0.0.17 → 0.0.18
raw patch · 2 files changed
+21/−3 lines, 2 files
Files
- hsinspect.cabal +2/−2
- library/HsInspect/Types.hs +19/−1
hsinspect.cabal view
@@ -1,13 +1,13 @@ cabal-version: 2.2 name: hsinspect-version: 0.0.17+version: 0.0.18 synopsis: Inspect Haskell source files. license: GPL-3.0-or-later license-file: LICENSE author: Tseen She maintainer: Tseen She copyright: 2019 Tseen She-tested-with: GHC ^>=8.4.4 || ^>=8.6.5 || ^>=8.8.3 || ^>=8.10.1+tested-with: GHC ^>=8.8.3 || ^>=8.10.4 category: Building description: Inspect @.hs@ files using the ghc api.
library/HsInspect/Types.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} @@ -19,6 +20,9 @@ import qualified Outputable as GHC import qualified Parser import qualified RnTypes as GHC+#if __GLASGOW_HASKELL__ >= 810+import qualified ErrUtils as GHC+#endif data Type = ProductType Text [Text] Bool Text [(Text, [Text])] -- ^^ type tparams newtype cons [(param types, [typarams])] | RecordType Text [Text] Bool Text [(Text, Text, [Text])] -- ^^ type tparams newtype cons [(fieldname, param type, [typarams])]@@ -84,7 +88,12 @@ GHC.NewType -> True GHC.DataType -> False renderTyParams :: GHC.LHsType GHC.GhcPs -> [Text]- renderTyParams tpe = showGhc <$> (GHC.freeKiTyVarsTypeVars $ GHC.extractHsTyRdrTyVars tpe)+ renderTyParams tpe = showGhc <$>+#if __GLASGOW_HASKELL__ >= 810+ GHC.extractHsTyRdrTyVars tpe+#else+ (GHC.freeKiTyVarsTypeVars $ GHC.extractHsTyRdrTyVars tpe)+#endif renderField :: GHC.GenLocated l (GHC.ConDeclField GHC.GhcPs) -> (Text, Text, [Text]) -- (name, type, [typarams]) renderField (GHC.L _ field) = let tpe = GHC.cd_fld_type field@@ -131,4 +140,13 @@ pure (types, sortOn (\(Comment _ s _) -> s) comments) +#if __GLASGOW_HASKELL__ >= 810+ GHC.PFailed st ->+ let errs = GHC.interppSP+ . GHC.pprErrMsgBagWithLoc+ . GHC.getErrorMessages st+ $ GHC.unsafeGlobalDynFlags+ in throwIO . userError $ "unable to parse " <> file <> " due to " <> GHC.showSDocUnsafe errs+#else GHC.PFailed _ _ err -> throwIO . userError $ "unable to parse " <> file <> " due to " <> GHC.showSDocUnsafe err+#endif