Reject nested predicates in impredicativity checking
authorRyan Scott <ryan.gl.scott@gmail.com>
Sun, 17 Mar 2019 13:37:27 +0000 (09:37 -0400)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Thu, 21 Mar 2019 00:10:57 +0000 (20:10 -0400)
commit8d18a873c5d7688c6e7d91efab6bb0d6f99393c6
tree9d66f0b2647ebd968ab9ec6d2cc0debe900da9a0
parent646e3dc20ebe25baae898a6b22895ddd015fc975
Reject nested predicates in impredicativity checking

When GHC attempts to unify a metavariable with a type containing
foralls, it will be rejected as an occurrence of impredicativity.
GHC was /not/ extending the same treatment to predicate types, such
as in the following (erroneous) example from #11514:

```haskell
foo :: forall a. (Show a => a -> a) -> ()
foo = undefined
```

This will attempt to instantiate `undefined` at
`(Show a => a -> a) -> ()`, which is impredicative. This patch
catches impredicativity arising from predicates in this fashion.

Since GHC is pickier about impredicative instantiations, some test
cases needed to be updated to be updated so as not to fall afoul of
the new validity check. (There were a surprising number of
impredicative uses of `undefined`!) Moreover, the `T14828` test case
now has slightly less informative types shown with `:print`. This is
due to a a much deeper issue with the GHCi debugger (see #14828).

Fixes #11514.
20 files changed:
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcUnify.hs
testsuite/tests/dependent/should_compile/dynamic-paper.hs
testsuite/tests/dependent/should_compile/dynamic-paper.stderr
testsuite/tests/ghci.debugger/scripts/print027.stdout
testsuite/tests/ghci/scripts/T12447.script
testsuite/tests/ghci/scripts/T14828.stdout
testsuite/tests/indexed-types/should_compile/T4358.hs
testsuite/tests/indexed-types/should_fail/T5934.stderr
testsuite/tests/polykinds/T11142.stderr
testsuite/tests/polykinds/T14270.hs
testsuite/tests/polykinds/T9569.hs
testsuite/tests/th/T11452.stderr
testsuite/tests/typecheck/should_compile/T12427a.stderr
testsuite/tests/typecheck/should_fail/T10194.stderr
testsuite/tests/typecheck/should_fail/T11514.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T11514.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T12563.stderr
testsuite/tests/typecheck/should_fail/T12589.stderr
testsuite/tests/typecheck/should_fail/all.T