Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Hide a warning for one-constructor sum types

  • Loading branch information...
commit c1a29600f5f15628ae1d6a5179190734110a582d 1 parent f52a5a4
@snoyberg snoyberg authored
View
6 persistent-template/Database/Persist/TH.hs
@@ -473,15 +473,15 @@ mkLensClauses t = do
(NormalB $ lens' `AppE` getter `AppE` setter)
[]
where
+ emptyMatch = Match WildP (NormalB $ VarE 'error `AppE` LitE (StringL "Tried to use fieldLens on a Sum type")) []
getter = LamE
[ ConP 'Entity [WildP, VarP valName]
] $ CaseE (VarE valName)
- [ Match (ConP (sumConstrName t f) [VarP xName]) (NormalB $ VarE xName) []
+ $ Match (ConP (sumConstrName t f) [VarP xName]) (NormalB $ VarE xName) []
-- FIXME It would be nice if the types expressed that the Field is
-- a sum type and therefore could result in Maybe.
- , Match WildP (NormalB $ VarE 'error `AppE` LitE (StringL "Tried to use fieldLens on a Sum type")) []
- ]
+ : if length (entityFields t) > 1 then [emptyMatch] else []
setter = LamE
[ ConP 'Entity [VarP keyName, WildP]
, VarP xName
View
2  persistent-template/persistent-template.cabal
@@ -1,5 +1,5 @@
name: persistent-template
-version: 1.1.3
+version: 1.1.3.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Please sign in to comment.
Something went wrong with that request. Please try again.