Skip to content

UndecidableSuperClasses sometimes additionally needs UndecidableInstances

When I say

{-# LANGUAGE TypeFamilies, UndecidableSuperClasses #-}

module Bug where

import Data.Kind

type family F a :: Constraint

class F a => C a

I get

Bug.hs:9:1: error:
    • Illegal constraint ‘F a’ in a superclass context
        (Use UndecidableInstances to permit this)
    • In the context: F a
      While checking the super-classes of class ‘C’
      In the class declaration for ‘C’

Indeed, UndecidableInstances allows my program to be accepted. But I think UndecidableSuperClasses should be enough.

Once we agree about the design, the fix is easy: delete this bit of GHC.Tc.Validity.check_irred_pred:

         -- Make sure it is OK to have an irred pred in this context
         -- See Note [Irreducible predicates in superclasses]
       ; failIfTcM (is_superclass ctxt
                    && not (xopt LangExt.UndecidableInstances dflags)
                    && has_tyfun_head pred)
                   (predSuperClassErr env pred)

and the corresponding Note.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information