Skip to content

Panic when checking type family dependency

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds, TypeFamilies, TypeFamilyDependencies, PolyKinds #-}
module Bug where

data T = Foo | Bar

type family F (ns :: T) (ret :: k) = (r :: k) | r -> ret where
    F Foo r = r
    F Bar r = r

On a GHC as of e2f0094c, with sufficient sanity checks (i.e. compiled with -DDEBUG), this crashes with:

<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.5.20220719:
        ASSERT failed!
  in_scope InScope {r_a9 k_aJ}
  tenv [a9 :-> r_a9, aa :-> r_a9, aJ :-> k_aJ]
  cenv []
  tys [k_aN, r_aa]
  cos []
  needInScope {k_aN}
  Call stack:
      CallStack (from HasCallStack):
        assertPpr, called at compiler/GHC/Core/TyCo/Subst.hs:645:5 in ghc:GHC.Core.TyCo.Subst
        checkValidSubst, called at compiler/GHC/Core/TyCo/Subst.hs:694:17 in ghc:GHC.Core.TyCo.Subst
        substTys, called at compiler/GHC/Core/FamInstEnv.hs:568:25 in ghc:GHC.Core.FamInstEnv

Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information