Description
I have a very strange issue with doctest. It is so strange that makes me believe that it could be a bug in ghc instead, but I can't really confirm it, so I am reporting it here.
I've used doctest successfully as a cabal test suite setup for many years, which unfortunately only worked in ghc-8.2 through ghc-8.8 and breaks with strange errors starting with ghc-8.10:
test-suite doctests
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: doctests.hs
build-depends: base >= 4.9 && < 5
, doctest >=0.15
...
Considering that those GHC versions are pretty old, I decided to switch to a more appropriate setup that I learned from @sol of invoking doctest
as a cabal repl ... --with-compiler=doctest
This change in setup can be found in this PR: massiv#150. However, when I do this and run the ./scripts/doctest.sh
script, I get a huge portion of my doctests fail with nearly identical error:
$ cabal build massiv && ./scripts/doctest.sh
...
src/Data/Massiv/Core/Common.hs:1126: failure in expression `import Data.Massiv.Array'
expected:
but got: <no location info>: error: [GHC-87110]
^
Could not load module ‘Data.Massiv.Array’.
It is a member of the hidden package ‘massiv-1.0.5.0’.
Perhaps you need to add ‘massiv’ to the build-depends in your .cabal file.
Examples: 715 Tried: 338 Errors: 0 Failures: 107
Error: [Cabal-7125]
repl failed for massiv-1.0.5.0.
GHC-9.10.2 and latest doctest-0.24.0 was used for reproduction. (GHC-9.12 has changed how exceptions are handled, which affects some of my doctests, but issue at hand is still present)
I've tried rewriting doctests in such a way that they didn't have to import the top level Data.Massiv.Array
module, which was mostly going fine, until I ran into a single module that for some reason did not let me work around this issue. This allowed me to narrow this issue to a single function.
Here is a PR with a reproducer that can be used for debugging this issue: massiv#151 that has a one line change:
replaceSlice dim i sl arr = do
...
- concatM dim [l, delay m', r]
+ undefined --concatM dim [l, delay m', r]
This one line change affects the outcome of all, but one of the of the previously unsuccessful doctests in the whole package. Two of the doctests produce an expected failure of undefined
, due to the change above, while another doctest still has a similar issue: "Could not load module". The important part in this bug report is that a seemingly benign change to the body of a function changed the outcome of the doctests from 107
failures to 1
failure.
I can't really explain what is going on, because I can't see anything special about this function. The only reason why I was able to find it was through bisecting the whole package and doing a bunch of trial and error runs.
$ cabal build massiv && ./scripts/doctest.sh
...
src/Data/Massiv/Array/Manifest/Vector.hs:174: failure in expression `import Data.Massiv.Array.Manifest.Vector (toVector)'
expected:
but got: <no location info>: error: [GHC-87110]
^
Could not load module ‘Data.Massiv.Array.Manifest.Vector’.
It is a member of the hidden package ‘massiv-1.0.5.0’.
Perhaps you need to add ‘massiv’ to the build-depends in your .cabal file.
src/Data/Massiv/Array/Ops/Transform.hs:919: failure in expression `replaceSlice 2 1 (arr' <!> (2, 3)) arr'
expected: Array DL Seq (Sz (3 :> 4 :. 5))
[ [ [ (0,0,0), (0,0,1), (0,0,2), (0,0,3), (0,0,4) ]
, [ (0,300,0), (0,300,100), (0,300,200), (0,300,300), (0,300,400) ]
, [ (0,2,0), (0,2,1), (0,2,2), (0,2,3), (0,2,4) ]
, [ (0,3,0), (0,3,1), (0,3,2), (0,3,3), (0,3,4) ]
]
, [ [ (1,0,0), (1,0,1), (1,0,2), (1,0,3), (1,0,4) ]
, [ (100,300,0), (100,300,100), (100,300,200), (100,300,300), (100,300,400) ]
, [ (1,2,0), (1,2,1), (1,2,2), (1,2,3), (1,2,4) ]
, [ (1,3,0), (1,3,1), (1,3,2), (1,3,3), (1,3,4) ]
]
, [ [ (2,0,0), (2,0,1), (2,0,2), (2,0,3), (2,0,4) ]
, [ (200,300,0), (200,300,100), (200,300,200), (200,300,300), (200,300,400) ]
, [ (2,2,0), (2,2,1), (2,2,2), (2,2,3), (2,2,4) ]
, [ (2,3,0), (2,3,1), (2,3,2), (2,3,3), (2,3,4) ]
]
]
but got: *** Exception: Prelude.undefined
^
CallStack (from HasCallStack):
undefined, called at src/Data/Massiv/Array/Ops/Transform.hs:951:3 in massiv-1.0.5.0-inplace:Data.Massiv.Array.Ops.Transform
src/Data/Massiv/Array/Ops/Transform.hs:961: failure in expression `replaceOuterSlice 1 (arr' !> 2) arr'
expected: Array DL Seq (Sz (3 :> 4 :. 5))
[ [ [ (0,0,0), (0,0,1), (0,0,2), (0,0,3), (0,0,4) ]
, [ (0,1,0), (0,1,1), (0,1,2), (0,1,3), (0,1,4) ]
, [ (0,2,0), (0,2,1), (0,2,2), (0,2,3), (0,2,4) ]
, [ (0,3,0), (0,3,1), (0,3,2), (0,3,3), (0,3,4) ]
]
, [ [ (200,0,0), (200,0,100), (200,0,200), (200,0,300), (200,0,400) ]
, [ (200,100,0), (200,100,100), (200,100,200), (200,100,300), (200,100,400) ]
, [ (200,200,0), (200,200,100), (200,200,200), (200,200,300), (200,200,400) ]
, [ (200,300,0), (200,300,100), (200,300,200), (200,300,300), (200,300,400) ]
]
, [ [ (2,0,0), (2,0,1), (2,0,2), (2,0,3), (2,0,4) ]
, [ (2,1,0), (2,1,1), (2,1,2), (2,1,3), (2,1,4) ]
, [ (2,2,0), (2,2,1), (2,2,2), (2,2,3), (2,2,4) ]
, [ (2,3,0), (2,3,1), (2,3,2), (2,3,3), (2,3,4) ]
]
]
but got: *** Exception: Prelude.undefined
^
CallStack (from HasCallStack):
undefined, called at src/Data/Massiv/Array/Ops/Transform.hs:951:3 in massiv-1.0.5.0-inplace:Data.Massiv.Array.Ops.Transform
Examples: 715 Tried: 711 Errors: 0 Failures: 3
Error: [Cabal-7125]
repl failed for massiv-1.0.5.0.