[GHC] #15814: Orphan Instance Overlap Error Message

GHC ghc-devs at haskell.org
Sat Oct 27 03:38:30 UTC 2018


#15814: Orphan Instance Overlap Error Message
-------------------------------------+-------------------------------------
           Reporter:  parsonsmatt    |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.4.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I'm working on moving some code around which unfortunately relies on
 orphan instances. This is the error I get:

 {{{
     /home/matt/Projects/cardano-sl/wallet-
 new/src/Cardano/Wallet/API/V1/Types.hs:1794:27: error:
         • Overlapping instances for Arbitrary
                                       (NonEmpty PaymentDistribution)
             arising from a use of ‘arbitrary’
           Matching instances:
             instance Arbitrary a => Arbitrary (NonEmpty a)
               -- Defined in ‘Pos.Util.Example’
             instance [safe] Arbitrary a => Arbitrary (NonEmpty a)
               -- Defined in ‘quickcheck-
 instances-0.3.18:Test.QuickCheck.Instances.Semigroup’
         • In the second argument of ‘(<*>)’, namely ‘arbitrary’
           In the first argument of ‘(<*>)’, namely
             ‘Payment <$> arbitrary <*> arbitrary’
           In the first argument of ‘(<*>)’, namely
             ‘Payment <$> arbitrary <*> arbitrary <*> arbitrary’
          |
     1794 |                       <*> arbitrary
          |                           ^^^^^^^^^

 }}}

 The first instance is the one that I have defined. The second is defined
 in library code upstream -- great! I want to use that one instead.
 However, I don't have a clue which module import is providing that
 instance.

 It would be *fantastic* if there was an additional line that says which
 module imported the instance, or brought it into scope. Multiple modules
 might do this; in this case, reporting any of them would be fine. Eg:

 {{{
     /home/matt/Projects/cardano-sl/wallet-
 new/src/Cardano/Wallet/API/V1/Types.hs:1794:27: error:
         • Overlapping instances for Arbitrary
                                       (NonEmpty PaymentDistribution)
             arising from a use of ‘arbitrary’
           Matching instances:
             instance Arbitrary a => Arbitrary (NonEmpty a)
               -- Defined in ‘Pos.Util.Example’
               -- and imported via
          |
      186 | import Cardano.Wallet.API.V1.Swagger.Example
          |
             instance [safe] Arbitrary a => Arbitrary (NonEmpty a)
               -- Defined in ‘quickcheck-
 instances-0.3.18:Test.QuickCheck.Instances.Semigroup’
               -- and imported via
          |
      ??? | this information would literally make my day
          |
         • In the second argument of ‘(<*>)’, namely ‘arbitrary’
           In the first argument of ‘(<*>)’, namely
             ‘Payment <$> arbitrary <*> arbitrary’
           In the first argument of ‘(<*>)’, namely
             ‘Payment <$> arbitrary <*> arbitrary <*> arbitrary’
          |
     1794 |                       <*> arbitrary
          |                           ^^^^^^^^^
 }}}

 I'll have to binary search the import list to try and figure out which
 module is bringing the instance into scope otherwise.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15814>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list