Opened 4 years ago

Closed 3 years ago

#11623 closed bug (fixed)

Wrong error message for type family definition that is wrong in multiple ways

Reported by: rwbarton Owned by: rdragon
Priority: low Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2089
Wiki Page:

Description

GHCi, version 8.1.20160212: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XTypeFamilies
Prelude> type family T where { Maybe T = Int }

<interactive>:2:23: error:
    • Too many parameters to T:
        T is unexpected;
        expected only no parameters
    • In the type family declaration for ‘T’

This error message is wrong ("Too many parameters to T").

Seems like GHC checks whether the equation Maybe T = Int has the right number of arguments before it checks whether it is actually headed by T. Then the error message is worded in a way that assumes the instance head actually was T.

The 7.10 error message was better in this regard:

<interactive>:3:23:
    Number of parameters must match family declaration; expected 0
    In the type family declaration for ‘T’

but it would be even better to generate the error below (that is generated once the number of arguments is correct) for the original program:

Prelude> type family T a where { Maybe (T ()) = Int }

<interactive>:5:25: error:
    • Mismatched type name in type family instance.
        Expected: T
          Actual: Maybe
    • In the type family declaration for ‘T’

We should generate that error before kind-checking the definition too.

I don't really understand the difference between these two cases though, so maybe my guess is wrong.

Prelude> type family T where { T () = Int }

<interactive>:10:23: error:
    • Too many parameters to T:
        () is unexpected;
        expected only no parameters
    • In the type family declaration for ‘T’
Prelude> type family T :: * -> * where { T () = Int }

<interactive>:11:33: error:
    • Number of parameters must match family declaration; expected 0
    • In the equations for closed type family ‘T’
      In the type family declaration for ‘T’

(As an aside, "expected only no parameters" is awkward, if there is some legitimate way to generate this message. It should just be "expected no parameters".)

Change History (6)

comment:1 Changed 3 years ago by rdragon

Owner: set to rdragon

comment:2 Changed 3 years ago by rdragon

Differential Rev(s): Phab:D2089

comment:3 Changed 3 years ago by bgamari

Status: newmerge

comment:4 Changed 3 years ago by bgamari

Milestone: 8.0.1

comment:5 Changed 3 years ago by Ben Gamari <ben@…>

In 46e8f199/ghc:

Fix a closed type family error message

Now we check whether a closed type family's equation is headed with
the correct type before we kind-check the equation.

Also, instead of "expected only no parameters" we now generate the
message "expected no parameters".

Fixes #11623.

Reviewers: simonpj, austin, bgamari

Reviewed By: simonpj, bgamari

Subscribers: simonpj, goldfire, thomie

Differential Revision: https://phabricator.haskell.org/D2089

GHC Trac Issues: #11623

comment:6 Changed 3 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.