Tighten checking for associated type instances
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 18 Apr 2016 14:14:40 +0000 (15:14 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 19 Apr 2016 07:38:47 +0000 (08:38 +0100)
commit8136a5cbfcd24647f897a2fae9fcbda0b1624035
tree8c5c8100cbe1b6552d5fbdd6819c9d4417fac48f
parent17eb2419c42c70d7436b6b8cff0cef705353bb4e
Tighten checking for associated type instances

This patch finishes off Trac #11450.  Following debate on that ticket,
the patch tightens up the rules for what the instances of an
associated type can look like.  Now they must match the instance
header exactly. Eg

   class C a b where
    type T a x b

With this class decl, if we have an instance decl
  instance C ty1 ty2 where ...
then the type instance must look like
     type T ty1 v ty2 = ...
with exactly
  - 'ty1' for 'a'
  -  'ty2' for 'b', and
  - a variable for 'x'

For example:

  instance C [p] Int
    type T [p] y Int = (p,y,y)

Previously we allowed multiple instance equations and now, in effect,
we don't since they would all overlap.  If you want multiple cases,
use an auxiliary type family.

This is consistent with the treatment of generic-default instances,
and the user manual always said "WARNING: this facility (multiple
instance equations may be withdrawn in the future".

I also improved error messages, and did other minor refactoring.
24 files changed:
compiler/rename/RnSource.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcTyClsDecls.hs
compiler/typecheck/TcValidity.hs
compiler/types/Type.hs
docs/users_guide/glasgow_exts.rst
testsuite/tests/ghci/scripts/T4175.hs
testsuite/tests/ghci/scripts/T4175.stdout
testsuite/tests/ghci/scripts/T6018ghcifail.stderr
testsuite/tests/indexed-types/should_compile/T10931.hs
testsuite/tests/indexed-types/should_fail/SimpleFail10.hs
testsuite/tests/indexed-types/should_fail/SimpleFail10.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/SimpleFail9.hs
testsuite/tests/indexed-types/should_fail/SimpleFail9.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/T11450.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/T11450.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/all.T
testsuite/tests/polykinds/T10570.stderr
testsuite/tests/th/T9692.hs
testsuite/tests/th/T9692.stderr
testsuite/tests/typecheck/should_fail/T6018fail.hs
testsuite/tests/typecheck/should_fail/T6018fail.stderr
testsuite/tests/typecheck/should_fail/T6018failclosed.stderr