Skip to content

When overlapping instances lead to a compile error, show import chains for the instances

Here's an example from work:

    • Overlapping instances for ToJSON BackupPhrase
        arising from a use of 'aesonRoundtripProp'
      Matching instances:
        instance ToJSON BackupPhrase
          -- Defined in 'Cardano.Wallet.Orphans.Aeson'
        instance ToJSON BackupPhrase
          -- Defined in 'Pos.Wallet.Aeson.ClientTypes'

Currently resolving such issues requires looking carefully at all imports and trying to guess which ones bring the instance into scope. It'd be quite helpful if the error was explicit about the import chain:

    • Overlapping instances for ToJSON BackupPhrase
        arising from a use of 'aesonRoundtripProp'
      Matching instances:
        instance ToJSON BackupPhrase
          -- Defined in 'Cardano.Wallet.Orphans.Aeson',
          --   imported by 'Cardano.Wallet.Orphans'
        instance ToJSON BackupPhrase
          -- Defined in 'Pos.Wallet.Aeson.ClientTypes',
          --   imported by 'Pos.Wallet.Web.Mode',
          --   and then by 'Cardano.Wallet.API.V1.Migration'

Thoughts?

I'm worried about two things here:

  1. Might these chains get too long?
  2. Is it sufficiently obvious that “imported by A and then by B” means that you have imported B and B imported A, and not vice-versa?
Trac metadata
Trac field Value
Version 8.2.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information