Test case for undersaturated newtype in Coercions
authorJoachim Breitner <mail@joachim-breitner.de>
Tue, 19 Nov 2013 12:01:27 +0000 (12:01 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Tue, 19 Nov 2013 12:01:27 +0000 (12:01 +0000)
This is related to #8541.

testsuite/tests/typecheck/should_fail/TcCoercibleFail3.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/TcCoercibleFail3.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T

diff --git a/testsuite/tests/typecheck/should_fail/TcCoercibleFail3.hs b/testsuite/tests/typecheck/should_fail/TcCoercibleFail3.hs
new file mode 100644 (file)
index 0000000..4caf1c2
--- /dev/null
@@ -0,0 +1,14 @@
+{-# LANGUAGE RoleAnnotations, RankNTypes, ScopedTypeVariables #-}
+
+import GHC.Prim (coerce, Coercible)
+
+newtype List a = List [a]
+data T f = T (f Int)
+
+newtype NT1 a = NT1 (a -> Int)
+newtype NT2 a = NT2 (a -> Int)
+
+foo :: T NT1 -> T NT2
+foo = coerce
+
+main = return ()
diff --git a/testsuite/tests/typecheck/should_fail/TcCoercibleFail3.stderr b/testsuite/tests/typecheck/should_fail/TcCoercibleFail3.stderr
new file mode 100644 (file)
index 0000000..d3d71e1
--- /dev/null
@@ -0,0 +1,7 @@
+
+TcCoercibleFail3.hs:12:7:
+    No instance for (Coercible NT1 NT2)
+      because ‛NT1’ and ‛NT2’ are different types.
+      arising from a use of ‛coerce’
+    In the expression: coerce
+    In an equation for ‛foo’: foo = coerce
index f14bb5f..749ea32 100644 (file)
@@ -319,6 +319,7 @@ test('T8262', normal, compile_fail, [''])
 test('TcCoercibleFail', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
 test('TcCoercibleFailSafe', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
 test('TcCoercibleFail2', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
+test('TcCoercibleFail3', when(compiler_lt('ghc', '7.7'), skip), compile_fail, [''])
 test('T8306', normal, compile_fail, [''])
 test('T8392a', normal, compile_fail, [''])
 test('T8428', normal, compile_fail, [''])