A constraint is both redundant and not deducible.
## Summary
GHC says that a constraint is redundant but then says the constraint is not deducible if I remove it.
## Steps to reproduce
From the [redundant-but-not-deducible](https://github.com/typechecker/redundant-but-not-deducible) package:
```haskell
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Werror=redundant-constraints #-}
module EventThing where
class Monad m => Event m where
thingsForEvent :: m [Int]
things :: Event m => m [Int]
things = thingsForEvent
-- class Thingy m where
class Monad m => Thingy m where
thingies :: m [Int]
-- instance Event m => Thingy m where
instance (Monad m, Event m) => Thingy m where
thingies = things
```
With `ghc-9.2.3 .. ghc-9.4.4` (but not in `ghc-9.6.1`) this module fails to
compile with the following error:
```
src/EventThing.hs error: [-Wredundant-constraints, -Werror=redundant-constraints]
• Redundant constraint: Monad m
• In the instance declaration for ‘Thingy m’
|
__ | instance (Monad m, Event m) => Thingy m where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Removing the redundant constraint, the module then also fails:
```
src/EventThing.hs: error:
• Could not deduce (Monad m)
arising from the superclasses of an instance declaration
from the context: Event m
bound by the instance declaration at src/EventThing.hs
Possible fix:
add (Monad m) to the context of the instance declaration
• In the instance declaration for ‘Thingy m’
|
__ | instance Event m => Thingy m where
| ^^^^^^^^^^^^^^^^^^^
```
Using the commented out class and instance lines, the module compiles without error.
## Expected behavior
If a constraint is redundant then removing it should be no problem.
## Environment
The `module EventThing` compiles with `ghc-8.10.7 .. ghc-9.2.2` fine but from
`ghc-9.2.3 .. ghc-9.4.4` it doesn't. With `ghc-9.6.1` it is good again.
* Operating System: ubuntu-22.04
* System Architecture: x86_64
issue