Permalink
Browse files

Hide a warning for one-constructor sum types

  • Loading branch information...
snoyberg committed Mar 20, 2013
1 parent f52a5a4 commit c1a29600f5f15628ae1d6a5179190734110a582d
Showing with 4 additions and 4 deletions.
  1. +3 −3 persistent-template/Database/Persist/TH.hs
  2. +1 −1 persistent-template/persistent-template.cabal
@@ -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
@@ -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>

0 comments on commit c1a2960

Please sign in to comment.