Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17838
Closed
Open
Created Feb 15, 2020 by Ryan Scott@RyanGlScottMaintainer

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
   |          ^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking