Type variables from instance declarations reinterpreted as existential type variables in associated data family instances
Summary
A simple program results in ghc panic, where instead it should be a compilation error.
[1 of 1] Compiling Main ( ghc-impossible.hs, ghc-impossible.o )
ghc: panic! (the 'impossible' happened)
(GHC version 8.8.3 for x86_64-unknown-linux):
mkTyConKindRepBinds.go(tyvar)
s_a10z[sk:1]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1159:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcTypeable.hs:536:9 in ghc:TcTypeable
Steps to reproduce
Here is a minimal example that triggers the bug
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Monad.ST
class Monad m => MonadRandom g m where
data GenM g :: (* -> *) -> *
type family StateToken (m :: * -> *) :: *
type instance StateToken IO = RealWorld
type instance StateToken (ST s) = s
newtype MutGen g = MutGen g
data MutVar s g
instance (s ~ StateToken m, Monad m) => MonadRandom (MutGen g) m where
newtype GenM (MutGen g) m = MutGenM (MutVar s g)
-- Correct version below compiles:
-- newtype GenM (MutGen g) m = MutGenM (MutVar (StateToken m) g)
Expected behavior
What do you expect the reproducer described above to do?
Environment
- GHC version used: 8.8.2 and 8.8.3
Optional:
- Operating System:
- System Architecture: