Opened 4 years ago

Closed 3 years ago

#9611 closed feature request (fixed)

Suggest the cause of "No instance" errors involving multiple versions of a package

Reported by: rwbarton Owned by: Yuras
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.8.3
Keywords: Cc: me@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1919
Wiki Page:


Suppose I have packages A-1.0, A-1.1, and B-1.0 built against A-1.0, and A (both versions) defines a type T which B defines to be an instance of some class C. If I load A-1.1 and B-1.0 into ghci and try to use the C T instance I will get a "No instance for C T" error, because T refers to A-1.1:T and B only defines an instance for A-1.0:T. However, if I don't realize this is what's going on, the error will be quite confusing as B appears to define an instance C T.

Or, A could define the class C, rather than the type T, with the same result.

This is quite common nowadays because there is a newer version of transformers ( than the one which ships with GHC ( and it's easy to end up installing mtl or lens against, and then some other package which pulls in

It would be nice to give a hint about what is going on, like

No instance for (MonadIO X) arising from a use of ‘liftIO’
In the expression: ...
Note: there is an instance transformers- X

Change History (8)

comment:1 Changed 4 years ago by simonpj

I expect this would be do-able (look in TcErrors), but it'd mean implementing a variant of the instance-matching code, to look for a match "by name" (where p1:A.B.T matches p2:A.B.T) rather than "by identity" where those two types are simply different.

I can offer guidance if someone tackles this.


comment:2 Changed 3 years ago by dmwit

Cc: me@… added

comment:3 Changed 3 years ago by Yuras

Owner: set to Yuras

I'll try to implement it unless someone already is on it.

comment:4 Changed 3 years ago by Yuras

Differential Rev(s): Phab:D1919
Status: newpatch

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

In 5fc06b9/ghc:

Suggest candidate instances in error message

See Trac #9611. In "No instance..." error message we suggest instances
for other types with the same occ name. It is usefull e.g. when we have
two different versions of the same package installed.

Test Plan: typecheck/should_fail/tcfail224

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #9611

comment:6 Changed 3 years ago by bgamari

Milestone: 8.0.1
Status: patchmerge
Type of failure: None/UnknownIncorrect warning at compile-time

comment:7 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In 4c6e95e4/ghc:

Small refactor and comments

Related to the fix to Trac #9611

comment:8 Changed 3 years ago by bgamari

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