GHC 9.2 fails to select an instance based on kinds in the presence of type families
Summary
I'm observing an instance resolution regression between GHC 9.0.2 and 9.2.4/9.2.5. Consider the following code:
{-# LANGUAGE KindSignatures, DataKinds, TypeFamilies, FlexibleInstances #-}
module Bug where
import Data.Kind
data D = D
type family F :: D -> Type
-- data F (x :: D)
class C f where
meth :: f
instance C (f (p :: D))
instance C (f (p :: Type))
_ = meth :: F 'D
_ = meth :: [Type]
The problem is in _ = meth :: F 'D
. By all accounts, F 'D
should match with f (p :: D)
, and it does in GHC 9.0. GHC 9.2, however, produces an inane error message:
error:
• Overlapping instances for C (F 'D) arising from a use of ‘meth’
Matching instances: instance C (f p) -- Defined at test.hs:12:10
There exists a (perhaps superclass) match:
(The choice depends on the result of evaluating ‘F’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
• In the expression: meth :: F 'D
In a pattern binding: _ = meth :: F 'D
Notice it only shows a single matching instance, but says there are many!
Switching type family F
for data F
makes it resolve the instance as expected again, so this is type-family-specific.
#21208 (closed), #21515 (closed) seem related.
Steps to reproduce
Try to compile/load the example code above.
Expected behavior
To typecheck.
Environment
- GHC version used: tested on 9.2.4 and 9.2.5