Unused type variable error misidentifies the name of the type variable
If you compile the following (erroneous) program on GHC 8.8.2 or later:
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
import Data.Kind
type Const (a :: Type) (b :: Type) = a
type family F (x :: a) :: Type where
forall a x. F x = Const Int a
You'll get the following error:
$ /opt/ghc/8.8.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:10: error:
• Type variable ‘a2’ is mentioned in the RHS,
but not bound on the LHS of the family instance
• In the equations for closed type family ‘F’
In the type family declaration for ‘F’
|
11 | forall a x. F x = Const Int a
| ^
This points to the type variable a
in the source code, but names it a2
in the error message! This appears to be the result of having a kind variable named a
in the type family header, since renaming that kind variable to something else makes the issue go away. For example, this variant of the program above:
type family F (x :: b) :: Type where
forall a x. F x = Const Int a
Gives a sensible error message:
$ /opt/ghc/8.8.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:10: error:
• Type variable ‘a’ is mentioned in the RHS,
but not bound on the LHS of the family instance
• In the equations for closed type family ‘F’
In the type family declaration for ‘F’
|
11 | forall a x. F x = Const Int a
| ^