Fix #14916 with an additional validity check in deriveTyData
authorRyan Scott <ryan.gl.scott@gmail.com>
Sun, 25 Mar 2018 19:34:05 +0000 (15:34 -0400)
committerBen Gamari <ben@smart-cactus.org>
Sun, 25 Mar 2018 19:34:21 +0000 (15:34 -0400)
commit20f14b4fd4eaf2c3ab375b8fc6d40ee9e6db94fd
treee742f9bba65bb1f5a9ed324284f25ad49bddb2fa
parent0703c00f7172608ee6d7ff7d422fe3755339e9bc
Fix #14916 with an additional validity check in deriveTyData

Manually-written instances and standalone-derived instances
have the benefit of having the `checkValidInstHead` function run over
them, which catches manual instances of built-in types like `(~)` and
`Coercible`. However, instances generated from `deriving` clauses
weren't being passed through `checkValidInstHead`, leading to
confusing results as in #14916.

`checkValidInstHead` also has additional validity checks for language
extensions like `FlexibleInstances` and `MultiParamTypeClasses`. Up
until now, GHC has never required these language extensions for
`deriving` clause, so to avoid unnecessary breakage, I opted to
suppress these language extension checks for `deriving` clauses, just
like we currently suppress them for `SPECIALIZE instance` pragmas.

Test Plan: make test TEST=T14916

Reviewers: goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14916

Differential Revision: https://phabricator.haskell.org/D4501
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
testsuite/tests/deriving/should_fail/T14916.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/T14916.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_fail/all.T