Skip to content

Instances become invisible across a component boundary

Summary

Reproduction repository: https://github.com/parsonsmatt/visibility

It seems like instances which are considered visible in the library component are no longer considered visible when reifying them in the test component.

The example repo essentially defines:

module C where

    class C a

module A where

    import C

    data A = A
    instance C A

module B where
    import C
    import A

    data B = B A
    instance C B

module T where
    import C
    import B ()

    data T = T
    instance C T

Based on what I've read on visible type class instances, I would expect that import T() would bring into visibility the instances for B and A as well. This is confirmed - in the library, I can write:

module Lib where

import C
import T ()
import Language.Haskell.TH

do
    instances <- reifyInstances ''C [VarP (mkName "a")]
    print instances

and it prints out instance declarations matching A, B, and T.

However, if I run the same code in the test suite for this package, then it only shows the instance C T - it only shows an instance if it was defined in the module that is being imported, not all the transitively imported instances.

Steps to reproduce

Reproduction repository: https://github.com/parsonsmatt/visibility

stack build or cabal build should both work. I've tested with GHC 8.10.3, 8.10.7, and 9.0.1.

Expected behavior

I would expect the instances to be visible just the same in a test-suite or library component.

Environment

  • GHC version used: 8.10.3, 8.10.7, 9.0.1

Optional:

  • Operating System: UBuntu
  • System Architecture: x86
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information