Skip to content
  • Ryan Scott's avatar
    Revise function arity mismatch errors involving TypeApplications · 84760976
    Ryan Scott authored
    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
    
    Reviewers: goldfire, austin, bgamari
    
    Reviewed By: goldfire
    
    Subscribers: rwbarton, thomie
    
    GHC Trac Issues: #13902
    
    Differential Revision: https://phabricator.haskell.org/D3868
    84760976