deriving-compat 0.5 → 0.5.1
raw patch · 3 files changed
+19/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +7/−3
- deriving-compat.cabal +1/−1
- src/Data/Deriving/Via/Internal.hs +11/−4
CHANGELOG.md view
@@ -1,12 +1,16 @@+### 0.5.1 [2018.07.11]+* Have `deriveGND`/`deriveVia` throw an error if an incorrect number of+ arguments are supplied to the type class.+ ### 0.5 [2018.07.01] * Backport the changes to `GeneralizedNewtypeDeriving` and `DerivingVia` code generation from [Trac #15290](https://ghc.haskell.org/trac/ghc/ticket/15290). As a result, code generated by `deriveGND` or `deriveVia` now requires the- `InstanceSigs` language extension. On the other hand, the generated code- no longer requires the `ImpredicativeTypes` extension (unless any class- methods use higher-rank types).+ `InstanceSigs` and `ScopedTypeVariables` language extensions. On the other+ hand, the generated code no longer requires the `ImpredicativeTypes`+ extension (unless any class methods use higher-rank types). * Allow building with `containers-0.6` and `template-haskell-2.14`. ### 0.4.3 [2018.06.16]
deriving-compat.cabal view
@@ -1,5 +1,5 @@ name: deriving-compat-version: 0.5+version: 0.5.1 synopsis: Backports of GHC deriving extensions description: Provides Template Haskell functions that mimic deriving extensions that were introduced or modified in recent versions
src/Data/Deriving/Via/Internal.hs view
@@ -17,7 +17,7 @@ module Data.Deriving.Via.Internal where #if MIN_VERSION_template_haskell(2,12,0)-import Control.Monad ((<=<))+import Control.Monad ((<=<), unless) import Data.Deriving.Internal import qualified Data.Map as M@@ -122,13 +122,20 @@ Nothing -> etaReductionError instanceTy Nothing -> fail $ "Not a newtype: " ++ nameBase dataName _ -> fail $ "Not a data type: " ++ pprint dataTy- concat . catMaybes <$> traverse (deriveViaDecs' clsTvbs clsArgs repTy) clsDecs+ concat . catMaybes <$> traverse (deriveViaDecs' clsName clsTvbs clsArgs repTy) clsDecs (_, _) -> fail $ "Cannot derive instance for nullary class " ++ pprint clsTy _ -> fail $ "Not a type class: " ++ pprint clsTy _ -> fail $ "Malformed instance: " ++ pprint instanceTy -deriveViaDecs' :: [TyVarBndr] -> [Type] -> Type -> Dec -> Q (Maybe [Dec])-deriveViaDecs' clsTvbs clsArgs repTy = go+deriveViaDecs' :: Name -> [TyVarBndr] -> [Type] -> Type -> Dec -> Q (Maybe [Dec])+deriveViaDecs' clsName clsTvbs clsArgs repTy dec = do+ let numExpectedArgs = length clsTvbs+ numActualArgs = length clsArgs+ unless (numExpectedArgs == numActualArgs) $+ fail $ "Mismatched number of class arguments"+ ++ "\n\tThe class " ++ nameBase clsName ++ " expects " ++ show numExpectedArgs ++ " argument(s),"+ ++ "\n\tbut was provided " ++ show numActualArgs ++ " argument(s)."+ go dec where go :: Dec -> Q (Maybe [Dec])