derive-has-field 0.1.1.0 → 0.1.2.0
raw patch · 3 files changed
+15/−11 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- derive-has-field.cabal +1/−1
- src/DeriveHasField.hs +5/−4
- test/DeriveHasFieldSpec.hs +9/−6
derive-has-field.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: derive-has-field-version: 0.1.1.0+version: 0.1.2.0 synopsis: Derive HasField instances with Template Haskell description: A Template Haskell function to derive HasField instances to utilize OverloadedRecordDot more effectively. category: Template Haskell
src/DeriveHasField.hs view
@@ -81,14 +81,15 @@ when (datatypeInfo.datatypeVariant `Foldable.notElem` [Datatype, Newtype]) $ fail "deriveHasField: only supports data and newtype" - -- We only support data types with field names and concrete types- let isConcreteType = \case+ -- We only support data types with concrete types or plain polymorphic variables+ let isSupportedType = \case ConT _ -> True AppT _ _ -> True+ VarT _ -> True _ -> False recordConstructorNames <- getRecordConstructorFieldNames constructorInfo- unless (Foldable.all isConcreteType constructorInfo.constructorFields) $- fail "deriveHasField: only supports concrete field types"+ forM_ (Foldable.find (not . isSupportedType) constructorInfo.constructorFields) $ \unsupportedType ->+ fail $ "deriveHasField: only supports simple field types, but " <> pprint unsupportedType <> " is not" -- Build the instances let constructorNamesAndTypes :: [(Name, Type)]
test/DeriveHasFieldSpec.hs view
@@ -48,8 +48,9 @@ } data OtherType a b = OtherType- { otherTypeField :: Maybe a- , otherTypeOtherField :: Either a b+ { otherTypeField :: a+ , otherTypeMaybeField :: Maybe a+ , otherTypeEitherField :: Either a b } DeriveHasField.deriveHasField ''OtherType@@ -57,8 +58,9 @@ otherType :: OtherType Int String otherType = OtherType- { otherTypeField = Just 0- , otherTypeOtherField = Right "hello"+ { otherTypeField = 0+ , otherTypeMaybeField = Just 0+ , otherTypeEitherField = Right "hello" } data OtherTypePrefix a b = OtherTypePrefix@@ -126,8 +128,9 @@ someType.someMaybeField `shouldBe` Just 0 someType.someEitherField `shouldBe` Right 0 it "compiles and gets the right field" $ do- otherType.field `shouldBe` Just 0- otherType.otherField `shouldBe` Right "hello"+ otherType.field `shouldBe` 0+ otherType.maybeField `shouldBe` Just 0+ otherType.eitherField `shouldBe` Right "hello" it "compiles and gets the right field" $ do kindedType.withKind `shouldBe` Just () kindedType.withSymbol `shouldBe` Proxy @"hello"