summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@richarde.dev>2021-11-03 18:26:12 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-12 21:21:27 -0500
commit265ead8a7401e20d75ed4e476805508ea695f37f (patch)
tree9b1adbd7476b2b7242c5cac8ba5f14b78135812a /testsuite/tests/typecheck/should_compile
parenta57cc7548fc66a712f6f6cffdbda0a9c3c498829 (diff)
downloadhaskell-265ead8a7401e20d75ed4e476805508ea695f37f.tar.gz
Improve redundant-constraints warning
Previously, we reported things wrong with f :: (Eq a, Ord a) => a -> Bool f x = x == x saying that Eq a was redundant. This is fixed now, along with some simplification in Note [Replacement vs keeping]. There's a tiny bit of extra complexity in setImplicationStatus, but it's explained in Note [Tracking redundant constraints]. Close #20602
Diffstat (limited to 'testsuite/tests/typecheck/should_compile')
-rw-r--r--testsuite/tests/typecheck/should_compile/T20602.hs29
-rw-r--r--testsuite/tests/typecheck/should_compile/T20602.stderr40
-rw-r--r--testsuite/tests/typecheck/should_compile/T9939.stderr4
-rw-r--r--testsuite/tests/typecheck/should_compile/all.T1
4 files changed, 72 insertions, 2 deletions
diff --git a/testsuite/tests/typecheck/should_compile/T20602.hs b/testsuite/tests/typecheck/should_compile/T20602.hs
new file mode 100644
index 0000000000..03dd5af458
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T20602.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE TypeFamilies #-}
+
+{-# OPTIONS_GHC -Wredundant-constraints #-}
+
+module T20602 where
+
+f :: (Eq a, Ord a) => a -> Bool
+f x = x == x
+
+g :: (Eq a, Ord a) => a -> Bool
+g x = x > x
+
+h :: (Eq a, Ord a) => a -> Bool
+h x = x == x && x > x
+
+j :: (Eq a, a ~ b, Eq b) => a -> Bool
+j x = x == x
+
+k :: (Eq a, a ~ b, Eq b) => a -> Bool
+k _ = True
+
+l :: (Eq a, Ord a) => a -> Bool
+l _ = True
+
+m :: (a ~ b) => a -> a
+m x = x
+
+n :: (Eq a, b ~ a) => a -> Bool
+n x = (==) x x
diff --git a/testsuite/tests/typecheck/should_compile/T20602.stderr b/testsuite/tests/typecheck/should_compile/T20602.stderr
new file mode 100644
index 0000000000..5dacc5be5a
--- /dev/null
+++ b/testsuite/tests/typecheck/should_compile/T20602.stderr
@@ -0,0 +1,40 @@
+
+T20602.hs:7:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: Ord a
+ • In the type signature for:
+ f :: forall a. (Eq a, Ord a) => a -> Bool
+
+T20602.hs:10:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: Eq a
+ • In the type signature for:
+ g :: forall a. (Eq a, Ord a) => a -> Bool
+
+T20602.hs:13:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: Eq a
+ • In the type signature for:
+ h :: forall a. (Eq a, Ord a) => a -> Bool
+
+T20602.hs:16:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: Eq b
+ • In the type signature for:
+ j :: forall a b. (Eq a, a ~ b, Eq b) => a -> Bool
+
+T20602.hs:19:6: warning: [-Wredundant-constraints]
+ • Redundant constraints: (Eq a, a ~ b, Eq b)
+ • In the type signature for:
+ k :: forall a b. (Eq a, a ~ b, Eq b) => a -> Bool
+
+T20602.hs:22:6: warning: [-Wredundant-constraints]
+ • Redundant constraints: (Eq a, Ord a)
+ • In the type signature for:
+ l :: forall a. (Eq a, Ord a) => a -> Bool
+
+T20602.hs:25:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: a ~ b
+ • In the type signature for:
+ m :: forall a b. (a ~ b) => a -> a
+
+T20602.hs:28:6: warning: [-Wredundant-constraints]
+ • Redundant constraint: b ~ a
+ • In the type signature for:
+ n :: forall a b. (Eq a, b ~ a) => a -> Bool
diff --git a/testsuite/tests/typecheck/should_compile/T9939.stderr b/testsuite/tests/typecheck/should_compile/T9939.stderr
index 3d4c964a15..3067cddbf6 100644
--- a/testsuite/tests/typecheck/should_compile/T9939.stderr
+++ b/testsuite/tests/typecheck/should_compile/T9939.stderr
@@ -5,7 +5,7 @@ T9939.hs:6:7: warning: [-Wredundant-constraints]
f1 :: forall a. (Eq a, Ord a) => a -> a -> Bool
T9939.hs:10:7: warning: [-Wredundant-constraints]
- • Redundant constraint: Eq a
+ • Redundant constraint: Ord a
• In the type signature for:
f2 :: forall a. (Eq a, Ord a) => a -> a -> Bool
@@ -15,6 +15,6 @@ T9939.hs:14:7: warning: [-Wredundant-constraints]
f3 :: forall a b. (Eq a, a ~ b, Eq b) => a -> b -> Bool
T9939.hs:21:7: warning: [-Wredundant-constraints]
- • Redundant constraint: Eq a
+ • Redundant constraint: Eq b
• In the type signature for:
f4 :: forall a b. (Eq a, Eq b) => a -> b -> Equal a b -> Bool
diff --git a/testsuite/tests/typecheck/should_compile/all.T b/testsuite/tests/typecheck/should_compile/all.T
index 7061f26779..9fbf11b641 100644
--- a/testsuite/tests/typecheck/should_compile/all.T
+++ b/testsuite/tests/typecheck/should_compile/all.T
@@ -572,6 +572,7 @@ test('T13458', normal, compile, [''])
test('T13490', normal, compile, [''])
test('T13474', normal, compile, [''])
test('T13524', normal, compile, [''])
+test('T20602', normal, compile, [''])
test('T13509', normal, compile, [''])
test('T13526', normal, compile, [''])
test('T13594', normal, compile_fail, [''])