diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+### 0.5.2 [2018.09.13]
+* Fix a bug (on GHC 8.7 and above) in which `deriveGND`/`deriveVia` would
+  generate ill-scoped code.
+
 ### 0.5.1 [2018.07.11]
 * Have `deriveGND`/`deriveVia` throw an error if an incorrect number of
   arguments are supplied to the type class.
diff --git a/deriving-compat.cabal b/deriving-compat.cabal
--- a/deriving-compat.cabal
+++ b/deriving-compat.cabal
@@ -1,5 +1,5 @@
 name:                deriving-compat
-version:             0.5.1
+version:             0.5.2
 synopsis:            Backports of GHC deriving extensions
 description:         Provides Template Haskell functions that mimic deriving
                      extensions that were introduced or modified in recent versions
diff --git a/src/Data/Deriving/Via/Internal.hs b/src/Data/Deriving/Via/Internal.hs
--- a/src/Data/Deriving/Via/Internal.hs
+++ b/src/Data/Deriving/Via/Internal.hs
@@ -184,7 +184,12 @@
 changeLast (x:xs) x' = x : changeLast xs x'
 
 stripOuterForallT :: Type -> Type
+#if __GLASGOW_HASKELL__ < 807
+-- Before GHC 8.7, TH-reified classes would put a redundant forall/class
+-- context in front of each method's type signature, so we have to strip them
+-- off here.
 stripOuterForallT (ForallT _ _ ty) = ty
+#endif
 stripOuterForallT ty               = ty
 
 decomposeType :: Type -> (Cxt, Type)
