summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-09-18 19:39:54 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-09-21 16:45:47 -0400
commit2f222b120e48df1b3d78f5501612d21c2a2dc470 (patch)
tree404dda6df93d8d3d72a23263ea78e5035fc9b97a /testsuite
parent1a0f8243efc9873a949bb6f082b4dfdf563fc1ea (diff)
downloadhaskell-2f222b120e48df1b3d78f5501612d21c2a2dc470.tar.gz
Disallow constraints in KindSigCtxt
This patch cleans up how `GHC.Tc.Validity` classifies `UserTypeCtxt`s that can only refer to kind-level positions, which is important for rejecting certain classes of programs. In particular, this patch: * Introduces a new `TypeOrKindCtxt` data type and `typeOrKindCtxt :: UserTypeCtxt -> TypeOrKindCtxt` function, which determines whether a `UserTypeCtxt` can refer to type-level contexts, kind-level contexts, or both. * Defines the existing `allConstraintsAllowed` and `vdqAllowed` functions in terms of `typeOrKindCtxt`, which avoids code duplication and ensures that they stay in sync in the future. The net effect of this patch is that it fixes #18714, in which it was discovered that `allConstraintsAllowed` incorrectly returned `True` for `KindSigCtxt`. Because `typeOrKindCtxt` now correctly classifies `KindSigCtxt` as a kind-level context, this bug no longer occurs.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/typecheck/should_fail/T18714.hs11
-rw-r--r--testsuite/tests/typecheck/should_fail/T18714.stderr7
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
3 files changed, 19 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_fail/T18714.hs b/testsuite/tests/typecheck/should_fail/T18714.hs
new file mode 100644
index 0000000000..9a111a2cc2
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T18714.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE ImpredicativeTypes #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE RankNTypes #-}
+module T18714 where
+
+import GHC.Exts
+
+type Id a = a
+
+type F = Id (Any :: forall a. Show a => a -> a)
diff --git a/testsuite/tests/typecheck/should_fail/T18714.stderr b/testsuite/tests/typecheck/should_fail/T18714.stderr
new file mode 100644
index 0000000000..e038e603e1
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T18714.stderr
@@ -0,0 +1,7 @@
+
+T18714.hs:11:14: error:
+ • Illegal constraint in a kind: forall a. Show a => a -> a
+ • In the first argument of ‘Id’, namely
+ ‘(Any :: forall a. Show a => a -> a)’
+ In the type ‘Id (Any :: forall a. Show a => a -> a)’
+ In the type declaration for ‘F’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 49a3cb8cec..6b10777f12 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -579,3 +579,4 @@ test('T18357a', normal, compile_fail, [''])
test('T18357b', normal, compile_fail, [''])
test('T18455', normal, compile_fail, [''])
test('T18534', normal, compile_fail, [''])
+test('T18714', normal, compile_fail, [''])