summaryrefslogtreecommitdiff
path: root/testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2023-04-29 18:59:10 +0200
committersheaf <sam.derbyshire@gmail.com>2023-04-29 20:23:06 +0200
commit57277662989b97dbf5ddc034d6c41ce39ab674ab (patch)
tree7d9fe1c4cb95a8bcf82490c354b5df0e9ab9037c /testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs
parent4eaf2c2a7682fa9933261f5eb25da9e2333c9608 (diff)
downloadhaskell-57277662989b97dbf5ddc034d6c41ce39ab674ab.tar.gz
Add the Unsatisfiable class
This commit implements GHC proposal #433, adding the Unsatisfiable class to the GHC.TypeError module. This provides an alternative to TypeError for which error reporting is more predictable: we report it when we are reporting unsolved Wanted constraints. Fixes #14983 #16249 #16906 #18310 #20835
Diffstat (limited to 'testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs')
-rw-r--r--testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs b/testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs
new file mode 100644
index 0000000000..90befcd5a9
--- /dev/null
+++ b/testsuite/tests/unsatisfiable/UnsatisfiableFail3.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE DataKinds #-}
+
+module UnsatisfiableFail3 where
+
+import GHC.TypeError
+
+
+-- This test makes sure we don't end up with duplication of error messages
+-- when adding Unsatisfiable contexts to classes with superclasses.
+
+-- Test 1: we add an Unsatisfiable context to both the class and its superclass.
+
+class Eq a => ReflexiveEq a where
+ reflexiveEq :: a -> a -> Bool
+ reflexiveEq = (==)
+
+instance Unsatisfiable (Text "Can't compare functions with (==)") => Eq (a -> b) where
+ (==) = unsatisfiable
+
+instance Unsatisfiable (Text "Can't compare functions with reflexiveEq") => ReflexiveEq (a -> b)
+
+type DoubleMsg = Text "Equality is not reflexive on Double"
+instance Unsatisfiable DoubleMsg => ReflexiveEq Double where
+ reflexiveEq = unsatisfiable @DoubleMsg
+
+foo = reflexiveEq 0 (0 :: Double)
+
+bar = reflexiveEq (\ (x :: Int) -> x + 1)
+
+
+-- Test 2: we add an Unsatisfiable context to the class, but not the superclass.
+
+class Eq a => ReflexiveEq' a where
+ reflexiveEq' :: a -> a -> Bool
+ reflexiveEq' = (==)
+
+instance Unsatisfiable (Text "Can't compare functions with reflexiveEq'") => ReflexiveEq' (a -> b)
+instance Unsatisfiable DoubleMsg => ReflexiveEq' Double where
+ reflexiveEq' = unsatisfiable @DoubleMsg
+
+foo' = reflexiveEq' 0 (0 :: Double)
+
+bar' = reflexiveEq' (\ (x :: Int) -> x + 1)