Opened 4 years ago

Closed 4 years ago

#9881 closed bug (fixed)

GHCi gives misleading error message when looking up info of ambiguous type

Reported by: RyanGlScott Owned by: simonpj
Priority: normal Milestone:
Component: GHCi Version: 7.8.3
Keywords: Cc: hvr
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case: ghci/scripts/T9881
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When GHCi imports multiple functions with the same name, using :i results in an ambiguous occurrence error:

> import Data.Text
> import Data.Text.Lazy
> :i length

Top level:
    Ambiguous occurrence ‘length’
    It could refer to either ‘Data.Text.Lazy.length’,
                             imported from ‘Data.Text.Lazy’
                          or ‘Prelude.length’,
                             imported from ‘Prelude’ (and originally defined in ‘GHC.List’)
                          or ‘Data.Text.length’, imported from ‘Data.Text’

However, if you use :i on a type name that has imported multiple times in GHCi, a misleading error is given:

> import Data.Text
> import Data.Text.Lazy
> :i Text

Top level: Not in scope: data constructor ‘Text’

The real problem is that the type name Text was imported twice with two different definitions, so the error should probably look something like this:

Top level:
    Ambiguous occurrence ‘Text’
    It could refer to either ‘Data.Text.Lazy.Text’,
                             imported from ‘Data.Text.Lazy’ (and originally defined in ‘Data.Text.Internal.Lazy’)
                          or ‘Data.Text.Text’,
                             imported from ‘Data.Text’ (and originally defined in ‘Data.Text.Internal‘)

Change History (3)

comment:1 Changed 4 years ago by simonpj

Owner: set to simonpj

Good point. I have a nice solution; more functinoality, less code.

Simon

comment:2 Changed 4 years ago by Simon Peyton Jones <simonpj@…>

In cf0a55d76cf945a97fc229b77d6e6177fb14125d/ghc:

For :info, return all matching Names, rather than complaining about ambiguity

This fixes Trac #9881, and gives more helpful output in the case of ambiguity.
Certainly more helpful than the positively-misleading error we get right now.

comment:3 Changed 4 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: ghci/scripts/T9881
Note: See TracTickets for help on using tickets.