summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2023-01-17 08:07:48 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2023-01-18 07:51:14 -0500
commitd79692c4e048fbe4336b78e43e6c4977cb109970 (patch)
tree18d761c31d681ea82aae132f0e45024a721b9e81
parentc45a5fffef2c76efbf5d3a009c3f6d0244a63f0d (diff)
downloadhaskell-wip/T22151.tar.gz
Add regression test for #22151wip/T22151
Issue #22151 was coincidentally fixed in commit aed1974e92366ab8e117734f308505684f70cddf (`Refactor the treatment of loopy superclass dicts`). This adds a regression test to ensure that the issue remains fixed. Fixes #22151.
-rw-r--r--testsuite/tests/warnings/should_compile/T22151.hs16
-rw-r--r--testsuite/tests/warnings/should_compile/all.T1
2 files changed, 17 insertions, 0 deletions
diff --git a/testsuite/tests/warnings/should_compile/T22151.hs b/testsuite/tests/warnings/should_compile/T22151.hs
new file mode 100644
index 0000000000..aa30b07e5f
--- /dev/null
+++ b/testsuite/tests/warnings/should_compile/T22151.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE UndecidableInstances #-}
+module T22151 where
+
+import Control.Monad.IO.Class (MonadIO(liftIO))
+
+class (Applicative m, Monad m) => C m where
+ m :: m ()
+
+-- This should not emit a -Wredundant-constraints warning. This is because
+-- GHC should not expand the superclasses of the Given constraint `MonadIO m`
+-- given that it is not Paterson-smaller than the instance head `C m`. (See
+-- Note [Recursive superclasses] in GHC.Tc.TyCl.Instance for more on what
+-- "Paterson-smaller" means.) As a result, we must provide the `Applicative m`
+-- and `Monad m` constraints explicitly.
+instance (Applicative m, Monad m, MonadIO m) => C m where
+ m = liftIO (pure ())
diff --git a/testsuite/tests/warnings/should_compile/all.T b/testsuite/tests/warnings/should_compile/all.T
index 3139a042e2..5a799ab885 100644
--- a/testsuite/tests/warnings/should_compile/all.T
+++ b/testsuite/tests/warnings/should_compile/all.T
@@ -53,4 +53,5 @@ test('DerivingTypeable', normal, compile, ['-Wderiving-typeable'])
test('T18862a', normal, compile, [''])
test('T18862b', normal, compile, [''])
test('T20312', normal, compile,['-Wall'])
+test('T22151', normal, compile, ['-Wredundant-constraints'])
test('T22759', normal, compile, [''])