Fix deriveTyData's kind unification when two kind variables are unified
authorRyanGlScott <ryan.gl.scott@gmail.com>
Wed, 11 May 2016 13:57:24 +0000 (15:57 +0200)
committerBen Gamari <ben@smart-cactus.org>
Thu, 12 May 2016 13:39:30 +0000 (15:39 +0200)
commite53f2180e89652c72e51ffa614c56294ba67cf37
treed55760338985aebb5c3ba879e32b0ec9d825b6de
parentc079de3c43704ea88f592e441389e520313e30ad
Fix deriveTyData's kind unification when two kind variables are unified

When `deriveTyData` attempts to unify two kind variables (which can
happen if both the typeclass and the datatype are poly-kinded), it
mistakenly adds an extra mapping to its substitution which causes the
unification to fail when applying the substitution. This can be
prevented by checking both the domain and the range of the original
substitution to see which kind variables shouldn't be put into the
domain of the substitution. A more in-depth explanation is included in
`Note [Unification of two kind variables in deriving]`.

Fixes #11837.

Test Plan: ./validate

Reviewers: simonpj, hvr, goldfire, niteria, austin, bgamari

Reviewed By: bgamari

Subscribers: niteria, thomie

Differential Revision: https://phabricator.haskell.org/D2117

GHC Trac Issues: #11837
compiler/typecheck/TcDeriv.hs
compiler/types/TyCoRep.hs
compiler/types/Type.hs
testsuite/tests/deriving/should_compile/T11837.hs [new file with mode: 0644]
testsuite/tests/deriving/should_compile/all.T