Skip to content

Commit

Permalink
Fix TH to support GHC 8.10's new unary tuple behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-abrar committed Nov 19, 2020
1 parent 55bacad commit 5c04f26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for aeson-gadt-th

## 0.2.5

* Support for GHC 8.10

## 0.2.4

* Support for GHC 8.8
Expand Down
2 changes: 1 addition & 1 deletion aeson-gadt-th.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library
, containers >= 0.5 && < 0.7
, dependent-sum >= 0.4 && < 0.8
, transformers >= 0.5 && < 0.6
, template-haskell >= 2.11.0 && < 2.16
, template-haskell >= 2.11.0 && < 2.17
, th-abstraction >= 0.2.8.0 && < 0.4
, th-extras >= 0.0.0.4 && < 0.1
if impl(ghc < 8.2)
Expand Down
12 changes: 9 additions & 3 deletions src/Data/Aeson/GADT/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import Data.List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe
import qualified Data.Set as Set
import Data.Some (Some (..))
import Language.Haskell.TH hiding (cxt)
import Language.Haskell.TH.Extras (nameOfBinder)
Expand Down Expand Up @@ -174,7 +173,12 @@ conMatchesToJSON opts allTopVars c = do
base = gadtConstructorModifier opts $ nameBase name
toJSONExp e = [| toJSON $(e) |]
vars <- lift . forM (constructorFields c) $ \_ -> newName "x"
let body = toJSONExp $ tupE [ [| base :: String |] , tupE $ map (toJSONExp . varE) vars ]
let body = toJSONExp $ tupE
[ [| base :: String |]
, case vars of
[v] -> toJSONExp $ varE v
vs -> tupE $ map (toJSONExp . varE) vs
]
_ <- conMatches ''ToJSON topVars lastVar c
lift $ match (conP name (map varP vars)) (normalB body) []

Expand Down Expand Up @@ -248,7 +252,9 @@ conMatches clsName topVars ixVar c = do
_ -> do
demandInstanceIfNecessary
return (VarP x, VarE x)
let pat = TupP (map fst vars)
let pat = case vars of
[v] -> fst v
vs -> TupP (map fst vs)
conApp = foldl AppE (ConE name) (map snd vars)
return (pat, conApp)

Expand Down

0 comments on commit 5c04f26

Please sign in to comment.