[commit: ghc] master: Fix DeriveAnyClass (Trac #9968) (af77089)

git at git.haskell.org git at git.haskell.org
Wed Dec 9 09:14:24 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/af77089b08b60c00128f0e5a65d18211ea62dfee/ghc

>---------------------------------------------------------------

commit af77089b08b60c00128f0e5a65d18211ea62dfee
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed Dec 9 09:07:46 2015 +0000

    Fix DeriveAnyClass (Trac #9968)
    
    The main issue concerned things like
    
       data T a = MkT a deriving( C Int )
    
    which is supposed to generate
    
       instance C Int (T a) where {}
    
    But the 'Int' argument (called cls_tys in the code) wasn't
    even being passed to inferConstraints and mk_data_eqn, so it
    really had no chance.   DeriveAnyClass came along after this
    code was written!
    
    Anyway I did quite a bit of tidying up in inferConstraints.
    
    Also I discovered that this case was not covered at all
    
       data T a b = MkT a b deriving( Bifunctor )
    
    What constraints should we generate for the instance context?
    We can deal with classes whose last arg has kind *, like Eq, Ord;
    or (* -> *), like Functor, Traversable.  But we really don't have
    a story for classes whose last arg has kind (* -> * -> *).
    
    So I augmented checkSideConditions to check for that and give
    a sensible error message.
    
    ToDo: update the user manual.


>---------------------------------------------------------------

af77089b08b60c00128f0e5a65d18211ea62dfee
 compiler/typecheck/TcDeriv.hs                      | 350 ++++++++++++---------
 compiler/typecheck/TcGenDeriv.hs                   |  15 +-
 testsuite/tests/deriving/should_compile/T9968.hs   |   7 +
 testsuite/tests/deriving/should_compile/all.T      |   1 +
 testsuite/tests/deriving/should_fail/T9968a.hs     |   8 +
 testsuite/tests/deriving/should_fail/T9968a.stderr |   6 +
 testsuite/tests/deriving/should_fail/all.T         |   2 +
 7 files changed, 232 insertions(+), 157 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 af77089b08b60c00128f0e5a65d18211ea62dfee


More information about the ghc-commits mailing list