Skip to content

Better error messages for misspelled modules

Motivation

Today I lost an hours having written the following code on 8.2.2, adding a field to some conversion function:

  Just something -> Just Api.MyType
    { Api.myField1 = convert (myField1 something)
    , Api.myField2 = convert (myField2 something)
    , API.myField3 = convert (myField3 something)
    }

The error:

    ‘API.myField3’ is not a (visible) field of constructor ‘Api.MyType’
    |
210 |     { API.myField3 = convert (myField3 something)
    |       ^^^^^^^^^^^^

The real issue here is the miss-spelling of API vs Api.

But the GHC error message makes it look like there's a proplem with myField3.

Proposal

  • Point out that there's no module API in scope at all!
  • Underline with ^^^ only the module, not the function name.
  • Perhaps even add a new suggestion ... did you mean 'Api'? to GHC's suggester.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information