summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck
diff options
context:
space:
mode:
authorSimon Peyton Jones <simon.peytonjones@gmail.com>2023-02-07 22:14:56 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-16 10:17:46 -0500
commit12965aba860676ec68cbced86eb18d6ec5cb83b3 (patch)
tree41985303917dfa8b42e8c2fe68e93b33715691c4 /testsuite/tests/typecheck
parent34cd308e23206e71b48e205970741746ed66ea8e (diff)
downloadhaskell-12965aba860676ec68cbced86eb18d6ec5cb83b3.tar.gz
Narrow the dont-decompose-newtype test
Following #22924 this patch narrows the test that stops us decomposing newtypes. The key change is the use of noGivenNewtypeReprEqs in GHC.Tc.Solver.Canonical.canTyConApp. We went to and fro on the solution, as you can see in #22924. The result is carefully documented in Note [Decomoposing newtype equalities] On the way I had revert most of commit 3e827c3f74ef76d90d79ab6c4e71aa954a1a6b90 Author: Richard Eisenberg <rae@cs.brynmawr.edu> Date: Mon Dec 5 10:14:02 2022 -0500 Do newtype unwrapping in the canonicaliser and rewriter See Note [Unwrap newtypes first], which has the details. It turns out that (a) 3e827c3f makes GHC behave worse on some recursive newtypes (see one of the tests on this commit) (b) the finer-grained test (namely noGivenNewtypeReprEqs) renders 3e827c3f unnecessary
Diffstat (limited to 'testsuite/tests/typecheck')
-rw-r--r--testsuite/tests/typecheck/should_compile/T22924.hs9
-rw-r--r--testsuite/tests/typecheck/should_compile/all.T2
-rw-r--r--testsuite/tests/typecheck/should_fail/T22924a.hs9
-rw-r--r--testsuite/tests/typecheck/should_fail/T22924a.stderr11
-rw-r--r--testsuite/tests/typecheck/should_fail/T22924b.hs10
-rw-r--r--testsuite/tests/typecheck/should_fail/T22924b.stderr10
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T3
7 files changed, 54 insertions, 0 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T22924.hs b/testsuite/tests/typecheck/should_compile/T22924.hs
new file mode 100644
index 0000000000..4945410fd8
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T22924.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE FlexibleInstances #-}
+module G where
+
+import Data.Functor.Const( Const )
+import Data.Coerce
+
+f :: Coercible (f a) a => Const a () -> Const (f a) ()
+f = coerce
+
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index ff603bbcf3..d687336044 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -860,3 +860,5 @@ test('T21501', normal, compile, [''])
test('T20666b', normal, compile, [''])
test('T22891', normal, compile, [''])
test('T22912', normal, compile, [''])
+test('T22924', normal, compile, [''])
+
diff --git a/testsuite/tests/typecheck/should_fail/T22924a.hs b/testsuite/tests/typecheck/should_fail/T22924a.hs
new file mode 100644
index 0000000000..80815d5492
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22924a.hs
@@ -0,0 +1,9 @@
+module T22924a where
+
+import Data.Coerce
+
+newtype R = MkR [R]
+
+f :: a -> [R]
+-- Should give a civilised error
+f = coerce
diff --git a/testsuite/tests/typecheck/should_fail/T22924a.stderr b/testsuite/tests/typecheck/should_fail/T22924a.stderr
new file mode 100644
index 0000000000..184058fb59
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22924a.stderr
@@ -0,0 +1,11 @@
+
+T22924a.hs:9:5: error: [GHC-10283]
+ • Couldn't match representation of type ‘a’ with that of ‘[R]’
+ arising from a use of ‘coerce’
+ ‘a’ is a rigid type variable bound by
+ the type signature for:
+ f :: forall a. a -> [R]
+ at T22924a.hs:7:1-13
+ • In the expression: coerce
+ In an equation for ‘f’: f = coerce
+ • Relevant bindings include f :: a -> [R] (bound at T22924a.hs:9:1)
diff --git a/testsuite/tests/typecheck/should_fail/T22924b.hs b/testsuite/tests/typecheck/should_fail/T22924b.hs
new file mode 100644
index 0000000000..09ca5d5c39
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22924b.hs
@@ -0,0 +1,10 @@
+module T22924b where
+
+import Data.Coerce
+
+newtype R = MkR [R]
+newtype S = MkS [S]
+
+f :: R -> S
+-- Blows the typechecker reduction stack
+f = coerce
diff --git a/testsuite/tests/typecheck/should_fail/T22924b.stderr b/testsuite/tests/typecheck/should_fail/T22924b.stderr
new file mode 100644
index 0000000000..ba4bd79198
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T22924b.stderr
@@ -0,0 +1,10 @@
+
+T22924b.hs:10:5: error:
+ • Reduction stack overflow; size = 201
+ When simplifying the following type: R
+ Use -freduction-depth=0 to disable this check
+ (any upper bound you could choose might fail unpredictably with
+ minor updates to GHC, so disabling the check is recommended if
+ you're sure that type checking should terminate)
+ • In the expression: coerce
+ In an equation for ‘f’: f = coerce
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index f8a3db350c..0dea0f43e0 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -667,3 +667,6 @@ test('T22570', normal, compile_fail, [''])
test('T22645', normal, compile_fail, [''])
test('T20666', normal, compile, ['']) # To become compile_fail after migration period (see #22912)
test('T20666a', normal, compile, ['']) # To become compile_fail after migration period (see #22912)
+test('T22924a', normal, compile_fail, [''])
+test('T22924b', normal, compile_fail, [''])
+