summaryrefslogtreecommitdiff
path: root/testsuite/tests/dependent/should_fail
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2018-06-17 12:28:23 -0400
committerBen Gamari <ben@smart-cactus.org>2018-06-17 12:42:56 -0400
commitc63754118cf6c3d0947d0c611f1db39c78acf1b7 (patch)
tree07572deedcf1a73fda2cd540426dcf14666587a4 /testsuite/tests/dependent/should_fail
parent793902e6891c30150fd3ac1e0e471269a4766780 (diff)
downloadhaskell-c63754118cf6c3d0947d0c611f1db39c78acf1b7.tar.gz
Provide a better error message for unpromotable data constructor contexts
Trac #14845 brought to light a corner case where a data constructor could not be promoted (even with `-XTypeInType`) due to an unpromotable constraint in its context. However, the error message was less than helpful, so this patch adds an additional check to `tcTyVar` catch unpromotable data constructors like these //before// they're promoted, and to give a sensible error message in such cases. Test Plan: make test TEST="T13895 T14845" Reviewers: simonpj, goldfire, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13895, #14845 Differential Revision: https://phabricator.haskell.org/D4728
Diffstat (limited to 'testsuite/tests/dependent/should_fail')
-rw-r--r--testsuite/tests/dependent/should_fail/PromotedClass.stderr3
-rw-r--r--testsuite/tests/dependent/should_fail/T13895.hs15
-rw-r--r--testsuite/tests/dependent/should_fail/T13895.stderr20
-rw-r--r--testsuite/tests/dependent/should_fail/T14845.stderr7
-rw-r--r--testsuite/tests/dependent/should_fail/T14845_fail1.hs10
-rw-r--r--testsuite/tests/dependent/should_fail/T14845_fail1.stderr7
-rw-r--r--testsuite/tests/dependent/should_fail/T14845_fail2.hs14
-rw-r--r--testsuite/tests/dependent/should_fail/T14845_fail2.stderr7
-rw-r--r--testsuite/tests/dependent/should_fail/T15215.stderr2
-rw-r--r--testsuite/tests/dependent/should_fail/all.T3
10 files changed, 86 insertions, 2 deletions
diff --git a/testsuite/tests/dependent/should_fail/PromotedClass.stderr b/testsuite/tests/dependent/should_fail/PromotedClass.stderr
index f0683309bc..4da1a32fca 100644
--- a/testsuite/tests/dependent/should_fail/PromotedClass.stderr
+++ b/testsuite/tests/dependent/should_fail/PromotedClass.stderr
@@ -1,5 +1,6 @@
PromotedClass.hs:10:15: error:
- • Illegal constraint in a type: Show a0
+ • Data constructor ‘MkX’ cannot be used here
+ (it has an unpromotable context ‘Show a’)
• In the first argument of ‘Proxy’, namely ‘( 'MkX 'True)’
In the type signature: foo :: Proxy ( 'MkX 'True)
diff --git a/testsuite/tests/dependent/should_fail/T13895.hs b/testsuite/tests/dependent/should_fail/T13895.hs
new file mode 100644
index 0000000000..5897cd8149
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T13895.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE TypeInType #-}
+module T13895 where
+
+import Data.Data (Data, Typeable)
+import Data.Kind
+
+dataCast1 :: forall (a :: Type).
+ Data a
+ => forall (c :: Type -> Type)
+ (t :: forall (k :: Type). Typeable k => k -> Type).
+ Typeable t
+ => (forall d. Data d => c (t d))
+ -> Maybe (c a)
+dataCast1 _ = undefined
diff --git a/testsuite/tests/dependent/should_fail/T13895.stderr b/testsuite/tests/dependent/should_fail/T13895.stderr
new file mode 100644
index 0000000000..0ae1710bf0
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T13895.stderr
@@ -0,0 +1,20 @@
+
+T13895.hs:12:23: error:
+ • Illegal constraint in a kind: Typeable k0
+ • In the first argument of ‘Typeable’, namely ‘t’
+ In the type signature:
+ dataCast1 :: forall (a :: Type).
+ Data a =>
+ forall (c :: Type -> Type)
+ (t :: forall (k :: Type). Typeable k => k -> Type).
+ Typeable t => (forall d. Data d => c (t d)) -> Maybe (c a)
+
+T13895.hs:13:38: error:
+ • Illegal constraint in a kind: Typeable k0
+ • In the first argument of ‘c’, namely ‘(t d)’
+ In the type signature:
+ dataCast1 :: forall (a :: Type).
+ Data a =>
+ forall (c :: Type -> Type)
+ (t :: forall (k :: Type). Typeable k => k -> Type).
+ Typeable t => (forall d. Data d => c (t d)) -> Maybe (c a)
diff --git a/testsuite/tests/dependent/should_fail/T14845.stderr b/testsuite/tests/dependent/should_fail/T14845.stderr
new file mode 100644
index 0000000000..3c11d15195
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T14845.stderr
@@ -0,0 +1,7 @@
+
+T14845.hs:19:16: error:
+ • Data constructor ‘MkA3’ cannot be used here
+ (it has an unpromotable context ‘Coercible a Int’)
+ • In the first argument of ‘SA’, namely ‘(MkA3 :: A Int)’
+ In the type ‘SA (MkA3 :: A Int)’
+ In the definition of data constructor ‘SMkA3’
diff --git a/testsuite/tests/dependent/should_fail/T14845_fail1.hs b/testsuite/tests/dependent/should_fail/T14845_fail1.hs
new file mode 100644
index 0000000000..46c1351027
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T14845_fail1.hs
@@ -0,0 +1,10 @@
+{-# Language PolyKinds, DataKinds, KindSignatures, GADTs, TypeInType, ConstraintKinds #-}
+module T14845_fail1 where
+
+import Data.Kind
+
+data Struct :: (k -> Constraint) -> (k -> Type) where
+ S :: cls a => Struct cls a
+
+data Foo a where
+ F :: Foo (S::Struct Eq a)
diff --git a/testsuite/tests/dependent/should_fail/T14845_fail1.stderr b/testsuite/tests/dependent/should_fail/T14845_fail1.stderr
new file mode 100644
index 0000000000..c1f1c8605d
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T14845_fail1.stderr
@@ -0,0 +1,7 @@
+
+T14845_fail1.hs:10:13: error:
+ • Data constructor ‘S’ cannot be used here
+ (it has an unpromotable context ‘cls a’)
+ • In the first argument of ‘Foo’, namely ‘(S :: Struct Eq a)’
+ In the type ‘Foo (S :: Struct Eq a)’
+ In the definition of data constructor ‘F’
diff --git a/testsuite/tests/dependent/should_fail/T14845_fail2.hs b/testsuite/tests/dependent/should_fail/T14845_fail2.hs
new file mode 100644
index 0000000000..4c5dac730f
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T14845_fail2.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeInType #-}
+module T14845_fail2 where
+
+import Data.Coerce
+import Data.Kind
+
+data A :: Type -> Type where
+ MkA :: Coercible a Int => A a
+
+data SA :: forall a. A a -> Type where
+ SMkA :: SA MkA
diff --git a/testsuite/tests/dependent/should_fail/T14845_fail2.stderr b/testsuite/tests/dependent/should_fail/T14845_fail2.stderr
new file mode 100644
index 0000000000..9fe733f374
--- /dev/null
+++ b/testsuite/tests/dependent/should_fail/T14845_fail2.stderr
@@ -0,0 +1,7 @@
+
+T14845_fail2.hs:14:14: error:
+ • Data constructor ‘MkA’ cannot be used here
+ (it has an unpromotable context ‘Coercible a Int’)
+ • In the first argument of ‘SA’, namely ‘MkA’
+ In the type ‘SA MkA’
+ In the definition of data constructor ‘SMkA’
diff --git a/testsuite/tests/dependent/should_fail/T15215.stderr b/testsuite/tests/dependent/should_fail/T15215.stderr
index 80181b44bd..53aff765a3 100644
--- a/testsuite/tests/dependent/should_fail/T15215.stderr
+++ b/testsuite/tests/dependent/should_fail/T15215.stderr
@@ -6,7 +6,7 @@ T15215.hs:9:3: error:
In the data type declaration for ‘A’
T15215.hs:12:14: error:
- • Illegal constraint in a type: Show (Maybe a0)
+ • Illegal constraint in a kind: Show (Maybe a0)
• In the first argument of ‘SA’, namely ‘MkA’
In the type ‘SA MkA’
In the definition of data constructor ‘SMkA’
diff --git a/testsuite/tests/dependent/should_fail/all.T b/testsuite/tests/dependent/should_fail/all.T
index 8e5185f1ae..2bfc39a6b8 100644
--- a/testsuite/tests/dependent/should_fail/all.T
+++ b/testsuite/tests/dependent/should_fail/all.T
@@ -19,6 +19,7 @@ test('T13601', normal, compile_fail, [''])
test('T13780a', normal, compile_fail, [''])
test('T13780c', [extra_files(['T13780b.hs'])],
multimod_compile_fail, ['T13780c', ''])
+test('T13895', normal, compile_fail, [''])
test('T14066', normal, compile_fail, [''])
test('T14066c', normal, compile_fail, [''])
test('T14066d', normal, compile_fail, [''])
@@ -26,6 +27,8 @@ test('T14066e', normal, compile_fail, [''])
test('T14066f', normal, compile_fail, [''])
test('T14066g', normal, compile_fail, [''])
test('T14066h', normal, compile_fail, [''])
+test('T14845_fail1', normal, compile_fail, [''])
+test('T14845_fail2', normal, compile_fail, [''])
test('InferDependency', normal, compile_fail, [''])
test('T15245', normal, compile_fail, [''])
test('T15215', normal, compile_fail, [''])