GHC internal error with StandaloneKindSignatures and lexically scoped type variable
The following program produces a GHC internal error on GHC 8.10.4 and later:
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeApplications #-}
module Bug where
import Data.Kind
type P :: k -> Type
data P a = MkP
type T :: k -> Constraint
class T (a :: j) where
f :: P a
f = MkP @j @a
$ /opt/ghc/9.0.1/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:15:12: error:
• GHC internal error: ‘j’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [agH :-> Type variable ‘a’ = a :: k,
aud :-> Type variable ‘k’ = k :: *]
• In the type ‘j’
In the expression: MkP @j @a
In an equation for ‘f’: f = MkP @j @a
|
15 | f = MkP @j @a
| ^
This also occurs if I change class T (a :: j)
to class T (a :: k)
(and change the default implementation of f
to f = MkP @k @a
accordingly). The error goes away if I remove the standalone kind signature for T
.