Opened 9 years ago

Closed 9 years ago

#4525 closed bug (fixed)

Type synonyms not expanded consistently in errors

Reported by: igloo Owned by:
Priority: normal Milestone: 7.4.1
Component: Compiler (Type checker) Version: 7.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

With this module:

type Foo = Int

x :: Char
x = f

f :: Foo
f = 5

GHC says:

g.hs:5:5:
    Couldn't match expected type `Char' with actual type `Int'
    Expected type: Char
      Actual type: Foo
    In the expression: f
    In an equation for `x': x = f

Note that the first line talks about Int, whereas the third line talks about Foo. I'd expect both to talk about Foo.

Change History (3)

comment:1 Changed 9 years ago by simonpj

Actually this is deliberate. The "couldn't match" part describes the actual incompatibility encountered. The "actual/expected" part describes the original types being unified. A more typical case might be

    Couldn't match expected type `Char' with actual type `Int'
    Expected type: Char -> a
      Actual type: Int -> a

It would be possible to make the first, "couldn't match", bit speak in terms of any immediate type synonym. That would make your original error look ok, and also:

    Couldn't match expected type `Char' with actual type `Foo'
    Expected type: Char -> a
      Actual type: Foo -> a

Would that be better? Anyone?

Simon

comment:2 Changed 9 years ago by igloo

That would be what I'd expect.

comment:3 Changed 9 years ago by igloo

Resolution: fixed
Status: newclosed

Fixed in HEAD by:

[Fix Trac #4525: report type errors in terms of the immediate type synonym
simonpj@microsoft.com**20101224082520
 Ignore-this: a3bd076bfe0e1c6f575b106f77f326c6
 
 This small change means that if you have
      type Age = Int
 and you try to unify Age and Bool, you'll get a complaint about
 not matching Age and Bool, rather than Int and Bool.  See the notes
 with Trac #4525
Note: See TracTickets for help on using tickets.