Check that a default type signature aligns with the non-default signature
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 30 Jan 2017 16:51:22 +0000 (11:51 -0500)
committerBen Gamari <ben@smart-cactus.org>
Mon, 30 Jan 2017 19:00:23 +0000 (14:00 -0500)
commit7363d5380e600e2ef868a069d5df6857d9e5c17e
treef6119aba56780edd79ce802fbab573b0966134fc
parent2ec1c834ca1129b69f4dd3e2586d9f318cbb3fa6
Check that a default type signature aligns with the non-default signature

Before, GHC was extremely permissive about the form a default type
signature could take on in a class declaration. Notably, it would accept
garbage like this:

  class Monad m => MonadSupply m where
    fresh :: m Integer
    default fresh :: MonadTrans t => t m Integer
    fresh = lift fresh

And then give an extremely confusing error message when you actually
tried to declare an empty instance of MonadSupply. We now do extra
validity checking of default type signatures to ensure that they align
with their non-default type signature counterparts. That is, a default
type signature is allowed to differ from the non-default one only in its
context - they must otherwise be alpha-equivalent.

Fixes #12918.

Test Plan: ./validate

Reviewers: goldfire, simonpj, austin, bgamari

Reviewed By: bgamari

Subscribers: mpickering, dfeuer, thomie

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

GHC Trac Issues: #12918
13 files changed:
compiler/typecheck/Inst.hs
compiler/typecheck/TcTyClsDecls.hs
compiler/typecheck/TcType.hs
docs/users_guide/8.2.1-notes.rst
docs/users_guide/glasgow_exts.rst
testsuite/tests/generics/T10361b.hs
testsuite/tests/typecheck/should_fail/T12151.stderr
testsuite/tests/typecheck/should_fail/T12918a.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T12918a.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T12918b.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T12918b.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T7437.stderr
testsuite/tests/typecheck/should_fail/all.T