Skip to content

Constraint not satisfied that is superclass of a class constraint

See master ticket #22912 (closed)

Summary

Here is a regression in the type checker between Alpha1 and Alpha2 of GHC-9.6.1.

Steps to reproduce

This is a simplified module:

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
module Memory where


newtype T a = Cons (Repr a)

class MV a where
   type Repr a


class IsType a where


class (IsType (Struct llvmValue)) => Memory llvmValue where
   type Struct llvmValue

instance (Memory (Repr a)) => Memory (T a) where
   type Struct (T a) = Struct (Repr a)

GHC-9.6.1-alpha1 accepts it whereas alpha2 fails with:

Memory.hs:19:10: error: [GHC-39999]
    • Could not deduce ‘IsType (Struct (Repr a))’
        arising from the superclasses of an instance declaration
      from the context: Memory (Repr a)
        bound by the instance declaration at Memory.hs:20:10-42
      Possible fix:
        If the constraint looks soluble from a superclass of the instance context,
        read 'Undecidable instances and loopy superclasses' in the user manual
    • In the instance declaration for ‘Memory (T a)’
   |
20 | instance (Memory (Repr a)) => Memory (T a) where
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expected behavior

The module should pass the typechecker.

Environment

  • GHC version used: GHC-9.6.1-alpha2
Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information