[Git][ghc/ghc][wip/T22151] Add regression test for #22151

Ryan Scott (@RyanGlScott) gitlab at gitlab.haskell.org
Wed Jan 18 00:32:35 UTC 2023



Ryan Scott pushed to branch wip/T22151 at Glasgow Haskell Compiler / GHC


Commits:
b6640f1d by Ryan Scott at 2023-01-17T19:32:26-05:00
Add regression test for #22151

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.

- - - - -


2 changed files:

- + testsuite/tests/warnings/should_compile/T22151.hs
- testsuite/tests/warnings/should_compile/all.T


Changes:

=====================================
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 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 ())


=====================================
testsuite/tests/warnings/should_compile/all.T
=====================================
@@ -53,3 +53,4 @@ 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'])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b6640f1d9a7a22112eb11da082880e9b4d6696bf

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b6640f1d9a7a22112eb11da082880e9b4d6696bf
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230117/9ec652cb/attachment-0001.html>


More information about the ghc-commits mailing list