Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for aeson-2 #260

Merged
merged 5 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
resolver: [nightly, lts-18, lts-16, lts-14]
stack_args:
- --resolver=nightly
- --resolver=lts-18
- --resolver=lts-16
- --resolver=lts-14
- --stack-yaml=stack-ghc-9.2.yaml

steps:
- name: Clone project
Expand All @@ -32,4 +37,4 @@ jobs:
ls C:/ProgramData/Chocolatey/bin/
rm C:/ProgramData/Chocolatey/bin/ghc*
fi
stack test --fast --no-terminal --resolver=${{ matrix.resolver }}
stack test --fast --no-terminal ${{ matrix.stack_args }}
9 changes: 8 additions & 1 deletion Text/Hamlet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bindingPattern (BindList is) = do
return (ListP patterns, concat scopes)
bindingPattern (BindConstr con is) = do
(patterns, scopes) <- fmap unzip $ mapM bindingPattern is
return (ConP (mkConName con) patterns, concat scopes)
return (conP (mkConName con) patterns, concat scopes)
bindingPattern (BindRecord con fields wild) = do
let f (Ident field,b) =
do (p,s) <- bindingPattern b
Expand All @@ -157,6 +157,13 @@ conToStr :: DataConstr -> String
conToStr (DCUnqualified (Ident x)) = x
conToStr (DCQualified (Module xs) (Ident x)) = intercalate "." $ xs ++ [x]

conP :: Name -> [Pat] -> Pat
#if MIN_VERSION_template_haskell(2,18,0)
conP name = ConP name []
#else
conP = ConP
#endif

-- Wildcards bind all of the unbound fields to variables whose name
-- matches the field name.
--
Expand Down
12 changes: 11 additions & 1 deletion Text/Julius.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -53,6 +54,9 @@ import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
import Text.Shakespeare
import Data.Aeson (Value, toJSON)
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
#endif
import Data.Aeson.Types (Value(..))
import Numeric (showHex)
import qualified Data.HashMap.Strict as H
Expand Down Expand Up @@ -117,12 +121,18 @@ encodeToTextBuilder =
V.foldr f (singleton ']') (V.unsafeTail v)
where f a z = singleton ',' <> go a <> z
go (Object m) = {-# SCC "go/Object" #-}
case H.toList m of
case fromObject m of
(x:xs) -> singleton '{' <> one x <> foldr f (singleton '}') xs
_ -> "{}"
where f a z = singleton ',' <> one a <> z
one (k,v) = string k <> singleton ':' <> go v

#if MIN_VERSION_aeson(2,0,0)
fromObject = H.toList . KeyMap.toHashMapText
#else
fromObject = H.toList
#endif

string :: T.Text -> Builder
string s = {-# SCC "string" #-} singleton '"' <> quote s <> singleton '"'
where
Expand Down
15 changes: 11 additions & 4 deletions Text/MkSizeType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ showInstanceDec name unit' = instanceD [] (instanceType "Show" name) [showDec]
x = mkName "x"
unit = LitE $ StringL unit'
showDec = FunD (mkName "show") [Clause [showPat] showBody []]
showPat = ConP name [VarP x]
showPat = conP name [VarP x]
showBody = NormalB $ AppE (AppE showSize $ VarE x) unit

numInstanceDec :: Name -> Dec
Expand All @@ -65,8 +65,8 @@ instanceType className name = AppT (ConT $ mkName className) (ConT name)

binaryFunDec :: Name -> String -> Dec
binaryFunDec name fun' = FunD fun [Clause [pat1, pat2] body []]
where pat1 = ConP name [VarP v1]
pat2 = ConP name [VarP v2]
where pat1 = conP name [VarP v1]
pat2 = conP name [VarP v2]
body = NormalB $ AppE (ConE name) result
result = AppE (AppE (VarE fun) (VarE v1)) (VarE v2)
fun = mkName fun'
Expand All @@ -75,7 +75,7 @@ binaryFunDec name fun' = FunD fun [Clause [pat1, pat2] body []]

unariFunDec1 :: Name -> String -> Dec
unariFunDec1 name fun' = FunD fun [Clause [pat] body []]
where pat = ConP name [VarP v]
where pat = conP name [VarP v]
body = NormalB $ AppE (ConE name) (AppE (VarE fun) (VarE v))
fun = mkName fun'
v = mkName "v"
Expand All @@ -92,3 +92,10 @@ notStrict = Bang NoSourceUnpackedness NoSourceStrictness

instanceD :: Cxt -> Type -> [Dec] -> Dec
instanceD = InstanceD Nothing

conP :: Name -> [Pat] -> Pat
#if MIN_VERSION_template_haskell(2,18,0)
conP name = ConP name []
#else
conP = ConP
#endif
14 changes: 11 additions & 3 deletions Text/Shakespeare/I18N.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand Down Expand Up @@ -186,7 +187,7 @@ toClauses prefix dt (lang, defs) =
(pat, bod) <- mkBody dt (prefix ++ constr def) (map fst $ vars def) (content def)
guard <- fmap NormalG [|$(return $ VarE a) == pack $(lift $ unpack lang)|]
return $ Clause
[WildP, ConP (mkName ":") [VarP a, WildP], pat]
[WildP, conP (mkName ":") [VarP a, WildP], pat]
(GuardedB [(guard, bod)])
[]

Expand Down Expand Up @@ -230,7 +231,7 @@ sToClause :: String -> String -> SDef -> Q Clause
sToClause prefix dt sdef = do
(pat, bod) <- mkBody dt (prefix ++ sconstr sdef) (map fst $ svars sdef) (scontent sdef)
return $ Clause
[WildP, ConP (mkName "[]") [], pat]
[WildP, conP (mkName "[]") [], pat]
(NormalB bod)
[]

Expand All @@ -241,10 +242,17 @@ defClause = do
d <- newName "msg"
rm <- [|renderMessage|]
return $ Clause
[VarP a, ConP (mkName ":") [WildP, VarP c], VarP d]
[VarP a, conP (mkName ":") [WildP, VarP c], VarP d]
(NormalB $ rm `AppE` VarE a `AppE` VarE c `AppE` VarE d)
[]

conP :: Name -> [Pat] -> Pat
#if MIN_VERSION_template_haskell(2,18,0)
conP name = ConP name []
#else
conP = ConP
#endif

toCon :: String -> SDef -> Con
toCon dt (SDef c vs _) =
RecC (mkName $ "Msg" ++ c) $ map go vs
Expand Down
2 changes: 1 addition & 1 deletion shakespeare.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ library
, ghc-prim
, bytestring
, directory >= 1.2
, aeson
, aeson < 3
, blaze-markup
, blaze-html
, exceptions
Expand Down
10 changes: 10 additions & 0 deletions stack-ghc-9.2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resolver: nightly-2021-11-14
compiler: ghc-9.2.1

extra-deps:
- aeson-2.0.2.0
- attoparsec-0.14.2
- base-compat-0.12.1
- base-compat-batteries-0.12.1
# https://github.com/simonmar/happy/issues/215
- happy-1.20.0