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

Support building with template-haskell-2.15 #77

Merged
merged 2 commits into from
Oct 2, 2019
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
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