Skip to content

Poor error message source location reporting with unsaturated type family

If you compile this program:

{-# LANGUAGE TypeFamilies #-}
module Bug where

newtype WrapChar f = MkWrapChar (f Char)
type family F a
type family T a
type instance T Int = WrapChar F

Then you'll get this error message:

$ /opt/ghc/8.6.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:7:15: error:
    • The type family ‘F’ should have 1 argument, but has been given none
    • In the type instance declaration for ‘T’
  |
7 | type instance T Int = WrapChar F
  |               ^

The thing is, the location of that caret is rather unfocused. It's pointing at T, but the real culprit is F!

I know that GHC can do better here because other error messages actually get this right. For instance, if you change the T Int instance to this:

type instance T Int = F

Then GHC will actually point to F in the resulting error message:

$ /opt/ghc/8.6.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:7:23: error:
    • Expecting one more argument to ‘F’
      Expected a type, but ‘F’ has kind ‘* -> *’
    • In the type ‘F’
      In the type instance declaration for ‘T’
  |
7 | type instance T Int = F
  |                       ^

If GHC can point to the right place in the source code in this situation, then it ought to get the earlier situation right as well.

Trac metadata
Trac field Value
Version 8.6.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information