From 8d18a873c5d7688c6e7d91efab6bb0d6f99393c6 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sun, 17 Mar 2019 09:37:27 -0400 Subject: 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. --- testsuite/tests/indexed-types/should_compile/T4358.hs | 4 ++-- testsuite/tests/indexed-types/should_fail/T5934.stderr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'testsuite/tests/indexed-types') diff --git a/testsuite/tests/indexed-types/should_compile/T4358.hs b/testsuite/tests/indexed-types/should_compile/T4358.hs index 0c05576812..cb05a1c1aa 100644 --- a/testsuite/tests/indexed-types/should_compile/T4358.hs +++ b/testsuite/tests/indexed-types/should_compile/T4358.hs @@ -6,6 +6,6 @@ type family T a t2 :: forall a. ((T a ~ a) => a) -> a t2 = t - + t :: forall a. ((T a ~ a) => a) -> a -t = undefined +t _ = undefined diff --git a/testsuite/tests/indexed-types/should_fail/T5934.stderr b/testsuite/tests/indexed-types/should_fail/T5934.stderr index 21af0d868a..e7448a9722 100644 --- a/testsuite/tests/indexed-types/should_fail/T5934.stderr +++ b/testsuite/tests/indexed-types/should_fail/T5934.stderr @@ -1,7 +1,7 @@ T5934.hs:12:7: error: • Cannot instantiate unification variable ‘a0’ - with a type involving foralls: (forall s. GenST s) -> Int + with a type involving polytypes: (forall s. GenST s) -> Int GHC doesn't yet support impredicative polymorphism • In the expression: 0 In an equation for ‘run’: run = 0 -- cgit v1.2.1