Revise function arity mismatch errors involving TypeApplications
ClosedPublic

Authored by RyanGlScott on Aug 17 2017, 10:58 AM.

Details

Summary

Currently, whenever you apply a function to too many arguments and
some of those arguments happen to be visible type applications, the error
message that GHC gives is rather confusing. Consider the message you receive
when typechecking id @Int 1 2:

The function `id` is applied to three arguments,
but its type `Int -> Int` has only one

This is baffling, since the two lines treat the visible type argument @Int
differently. The top line ("applied to three arguments") includes @Int,
whereas the bottom line ("has only one") excludes @Int from consideration.

There are multiple ways one could fix this, which I explain in an addendum to
Note [Herald for matchExpectedFunTys]. The approach adopted here is to change
the herald of this error message to include visible type arguments, and to
avoid counting them in the "applied to n arguments" part of the error. The end
result is that the new error message for id @Int 1 2 is now:

The expression `id @Int` is applied to two arguments,
but its type `Int -> Int` has only one
Test Plan

make test TEST=T13902

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
RyanGlScott created this revision.Aug 17 2017, 10:58 AM
goldfire accepted this revision.Aug 18 2017, 9:53 PM

I think this is a nice improvement. Correct the error message and then I approve.

compiler/typecheck/TcUnify.hs
101

You don't mean Trac #14110 there. You mean Trac #13902.

This revision is now accepted and ready to land.Aug 18 2017, 9:53 PM
  • Fix thinko in Note
RyanGlScott marked an inline comment as done.Aug 19 2017, 7:56 AM
This revision was automatically updated to reflect the committed changes.