Opened 11 years ago

Closed 8 years ago

Last modified 8 years ago

#2911 closed bug (wontfix)

Error messages have the wrong qualified names

Reported by: igloo Owned by:
Priority: normal Milestone: 7.2.1
Component: Compiler Version: 6.11
Keywords: Cc: id@…
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

This module:

module Foo where

import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
import qualified Data.ByteString.Lazy.Char8 as BSC

check :: ByteString -> Bool
check bs = BS.empty bs

produces this type error:

$ ghci -v0 q.hs

q.hs:9:11:
    Couldn't match expected type `ByteString -> Bool'
           against inferred type `ByteString'
    In the expression: BSC.empty bs
    In the definition of `check': check bs = BSC.empty bs

i.e. it claims that the expression is BSC.empty bs, whereas the program text says BS.empty bs.

Similarly, in this module:

module Foo where

import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
import Data.ByteString.Lazy.Char8

check :: ByteString -> Bool
check bs = BS.empty bs

the qualifier has disappeared completely in the error message:

$ ghci -v0 q.hs

q.hs:9:11:
    Couldn't match expected type `ByteString -> Bool'
           against inferred type `ByteString'
    In the expression: empty bs
    In the definition of `check': check bs = empty bs
Prelude> 

Change History (10)

comment:1 Changed 11 years ago by simonpj

This is a tricky one to fix. In both cases, the error message reports a valid way of referring to empty, just not the way that it was written in the source program.

The trouble is that the renamer has replaced the RdrName (which is more or less just a string) "BS.empty" by the Name Data.ByteString.Lazy.empty, which uniquely identifies the thing referred to (regardless of the string used to name it in the source program). That is, the renamer converts HsExpr RdrName to HsExpr Name. So the type checker doesn't even know exactly how you originally referred to it.

It'd be possible to retain the original text in the syntax tree, and perhaps better to do so. That is, make the renamer convert HsExpr RdrName to HsExpr (RdrName,Name). This'd add a bit of code, and slow down every compilation, so I'm not convinced it's worth it. Let's see what others think.

Simon

comment:2 Changed 11 years ago by claus

don't know whether this helps, but there was a similar problem when implementing the extended :browse! in GHCi (see compiler/ghci/InteractiveUI.hs, browseModule), and I settled for the compromise of listing the names and possible import routes separately. So in the output of ghc -e ':browse! *Foo' for the second example, one finds

..
-- imported via Data.ByteString.Lazy.Char8, BS
..
empty :: ByteString
..

comment:3 Changed 11 years ago by simonmar

Milestone: 6.12 branch
Priority: normallow

An alternative way to fix it would be to quote the program source text verbatim. We have a supposedly-accurate source span for the error message, so it would be possible to extract the actual program text from the source file and display that.

Not that I think it's worthwhile spending a lot of time to get this right, mind you.

comment:4 Changed 11 years ago by guest

Cc: id@… added

I vote for caring more about source-correct error messages!

I thought, if it makes compilation slower, maybe we can add a compiler flag to turn it on and off -- but I doubt that would actually work to preserve the fast case :-)

comment:5 Changed 10 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:6 Changed 10 years ago by igloo

Milestone: 6.12.36.14.1
Priority: lownormal
Type of failure: None/Unknown

See also #2245.

comment:7 Changed 9 years ago by igloo

Milestone: 7.0.17.0.2

comment:8 Changed 9 years ago by igloo

Milestone: 7.0.27.2.1

comment:9 Changed 8 years ago by igloo

Resolution: wontfix
Status: newclosed

I'm going to close this as not worth fixing. After all, errors are already differently laid out, don't include comments, etc.

comment:10 Changed 8 years ago by simonmar

See also #5868

Note: See TracTickets for help on using tickets.