Skip to content

Commit

Permalink
Merge pull request #77 from RyanGlScott/T76-direct
Browse files Browse the repository at this point in the history
Support building with template-haskell-2.15
  • Loading branch information
ddssff committed Oct 2, 2019
2 parents 6f3bb80 + 69c9a99 commit 2e38d92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Travis job script has been generated by a script via
#
# haskell-ci 'safecopy.cabal' '--allow-failures=>=8.8'
# haskell-ci 'safecopy.cabal'
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
Expand Down Expand Up @@ -36,8 +36,6 @@ matrix:
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-3.0"]}}
- compiler: ghc-8.0.2
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-3.0"]}}
allow_failures:
- compiler: ghc-8.8.1
before_install:
- HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
- WITHCOMPILER="-w $HC"
Expand Down Expand Up @@ -149,5 +147,5 @@ script:
- rm -f cabal.project.local
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output

# REGENDATA ["safecopy.cabal","--allow-failures=>=8.8"]
# REGENDATA ["safecopy.cabal"]
# EOF
20 changes: 20 additions & 0 deletions src/Data/SafeCopy/Derive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,19 @@ internalDeriveSafeCopy' deriveType versionId kindName tyName info = do
FamilyI _ insts -> do
decs <- forM insts $ \inst ->
case inst of
#if MIN_VERSION_template_haskell(2,15,0)
DataInstD context _ nty _kind cons _derivs ->
worker' (return nty) context [] (zip [0..] cons)

NewtypeInstD context _ nty _kind con _derivs ->
worker' (return nty) context [] [(0, con)]
#else
DataInstD context _name ty _kind cons _derivs ->
worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons)

NewtypeInstD context _name ty _kind con _derivs ->
worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)]
#endif
_ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, inst)
return $ concat decs
_ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, info)
Expand Down Expand Up @@ -276,15 +284,27 @@ internalDeriveSafeCopyIndexedType' deriveType versionId kindName tyName tyIndex'
FamilyI _ insts -> do
decs <- forM insts $ \inst ->
case inst of
#if MIN_VERSION_template_haskell(2,15,0)
DataInstD context _ nty _kind cons _derivs
| nty == foldl AppT (ConT tyName) tyIndex ->
worker' (return nty) context [] (zip [0..] cons)
#else
DataInstD context _name ty _kind cons _derivs
| ty == tyIndex ->
worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons)
#endif
| otherwise ->
return []

#if MIN_VERSION_template_haskell(2,15,0)
NewtypeInstD context _ nty _kind con _derivs
| nty == foldl AppT (ConT tyName) tyIndex ->
worker' (return nty) context [] [(0, con)]
#else
NewtypeInstD context _name ty _kind con _derivs
| ty == tyIndex ->
worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)]
#endif
| otherwise ->
return []
_ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, inst)
Expand Down

0 comments on commit 2e38d92

Please sign in to comment.