[commit: ghc] master: Make error when deriving an instance for a typeclass less misleading (d5a4e49)
git at git.haskell.org
git at git.haskell.org
Fri Oct 14 17:27:53 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/d5a4e49d657682eeb6e86ae464d281974ce2f5e2/ghc
>---------------------------------------------------------------
commit d5a4e49d657682eeb6e86ae464d281974ce2f5e2
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date: Fri Oct 14 10:40:56 2016 -0400
Make error when deriving an instance for a typeclass less misleading
Before, when you attempted to derive an instance for a typeclass,
e.g.,
```
class C1 (a :: Constraint) where
class C2 where
deriving instance C1 C2
```
GHC would complain that `C2`'s data constructors aren't in scope. But
that
makes no sense, since typeclasses don't have constructors! By refining
the
checks that GHC performs when deriving, we can make the error message a
little more sensible.
This also cleans up a related `DeriveAnyClass` infelicity. Before, you
wouldn't have been able to compile code like this:
```
import System.IO (Handle)
class C a
deriving instance C Handle
```
Since GHC was requiring that all data constructors of `Handle` be in
scope. But `DeriveAnyClass` doesn't even generate code that mentions
any data constructors, so this requirement is silly!
Fixes #11509.
Test Plan: make test TEST=T11509
Reviewers: simonpj, austin, bgamari
Reviewed By: simonpj, bgamari
Subscribers: thomie, simonpj
Differential Revision: https://phabricator.haskell.org/D2558
GHC Trac Issues: #11509
>---------------------------------------------------------------
d5a4e49d657682eeb6e86ae464d281974ce2f5e2
compiler/typecheck/TcDeriv.hs | 134 +++++++++++++++------
compiler/typecheck/TcDerivUtils.hs | 41 +++++--
docs/users_guide/8.2.1-notes.rst | 14 +++
docs/users_guide/glasgow_exts.rst | 11 ++
.../tests/deriving/should_compile/T11509_2.hs | 13 ++
.../tests/deriving/should_compile/T11509_3.hs | 9 ++
testsuite/tests/deriving/should_compile/all.T | 2 +
testsuite/tests/deriving/should_fail/T11509_1.hs | 52 ++++++++
.../tests/deriving/should_fail/T11509_1.stderr | 7 ++
testsuite/tests/deriving/should_fail/all.T | 2 +
10 files changed, 242 insertions(+), 43 deletions(-)
Diff suppressed because of size. To see it, use:
git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc d5a4e49d657682eeb6e86ae464d281974ce2f5e2
More information about the ghc-commits
mailing list