Ticket #5868 (closed bug: wontfix)

Opened 16 months ago

Last modified 16 months ago

Wrong error messages with qualified imports

Reported by: SimonHengel Owned by:
Priority: normal Milestone: _|_
Component: Compiler Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

If the same identifier is imported qualified twice, then only the second qualified name is used in error messages.

Steps to reproduce:

module Foo where
import qualified Bar
import qualified SomeOtherModule
foo :: Integer
foo = Bar.bar
module Bar (bar) where
bar :: Int
bar = 23
module SomeOtherModule (bar) where
import Bar

expected result:

Foo.hs:5:7:
    Couldn't match expected type `Integer' with actual type `Int'
    In the expression: Bar.bar
    In an equation for `foo': foo = Bar.bar

actual result:

Foo.hs:5:7:
    Couldn't match expected type `Integer' with actual type `Int'
    In the expression: SomeOtherModule.bar
    In an equation for `foo': foo = SomeOtherModule.bar

Change History

Changed 16 months ago by simonpj

  • difficulty set to Unknown
  • milestone set to _|_

Correct.

By the time we get to the type checker, GHC has forgotten how the entity was referenced and has simply recorded what entity was referenced. In this case it knows that you are talking about "the bar defined in module Bar", but has forgotten what you called it. Then when it prints the error message it tries to find some unambiguous name for it; hence the result.

It isn't perfect I grant you. One way to improve matters might be to change the HsExpr data type a bit, so instead of

data HsExpr id = HsVar     id 
                | ...

we have

data HsExpr id = HsVar     id RdrName
                | ...

so that every HsVar remembers how it was originally specified. That would catch 90% of the cases, but I worry about the others (eg qualified use of data constructors in patterns). A more thorough solution might be to make the renamer produce HsExpr (Name, RdrName) rather than HsExpr Name. But it's also pretty expensive.

My gut feel is to let sleeping dogs lie unless more people pipe up that this is really painful.

Simon

Changed 16 months ago by simonmar

  • status changed from new to closed
  • resolution set to wontfix

We have an old ticket about this: #2911, which we closed as wontfix. Doing the same here.

Note: See TracTickets for help on using tickets.