3
votes

Edit: very small repro available https://github.com/dten/CouldntMatchTypeRepro

stack test worked fine on stack LTS-8.24 (ghc 8.0.2) and i tried to change to LTS-10.5 (ghc 8.2.2). It now fails type checking and the error message is less than helpful.

The MyId types listed literally are the same type, declared in my-model makeId is in a testing-help package that references my-model and this code is in a test package that references both.

Moving the function to the my-model package results in no error (but I don't want to, and I have the problem with other types even in the same package (always a usage in the test package)) I have read through migration info to 8.2 but nothing stood out. Any pointer in the correct direction is appreciated :) thanks

test\Spec.hs:785:11: error:
    * Couldn't match type `my-model-0.0.0:Types.Ids.MyId'
                     with `MyId'
      NB: `MyId'
            is defined in `Types.Ids' in package `my-model-0.0.0'
          `my-model-0.0.0:Types.Ids.MyId'
            is defined in `Types.Ids' in package `my-model-0.0.0'
      Expected type: UserId
        Actual type: my-model-0.0.0:Types.Ids.MyId
    * In the expression: makeId "19186adb-26e5-4901-956c-f3ba11fc016d"
      In an equation for `userId':
          userId = makeId "19186adb-26e5-4901-956c-f3ba11fc016d"
    |
785 | userId = makeId "19186adb-26e5-4901-956c-f3ba11fc016d"
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

edits: I have tried deleting .stack-work and even ~/stack-root

the packages layout is as follows:

package: my-model
  library
  test-suite test
     deps: my-model, testing-help
package: testing-help
  library
     deps: my-model

no version requirements are set (because it's stack LTS style) and all versions of my packages are 0.0.0

edit2: they're all in 1 stack.yaml

edit3: sorry got package deps wrong

1
One is the one imported from my-model-0.0.0 and the other is one you apparently have defined locally? - Willem Van Onsem
When ghc prefixes a type with a package+version in the error message, it usually means you are depending on two different versions of the same package. GHC allows that, but it's easy to mix them up. Try to redo your dependencies such that you only depend on one version of my-model. - Carl
Oh, since they're both listed as my-model-0.0.0, I'm betting you made changes to the package without updating the version, recompiled it, and didn't recompile everything that depended on it. This is a dangerous workflow. (ghc distinguishes packages by a package-id hash internally, so it can tell the packages apart. It only displays version numbers, so you can't tell them apart. This is a problem.) - Carl
i added some details about package versions - dten
I'm getting the suspicion this is because 10.5 changes Cabal to version 2, which is resulting in more modules being built as part of the test suite which then clash with the library versions. Can't see it in any Cabal migration guide though - dten

1 Answers

1
votes

That appears to be a bug in Cabal, or at least a missing feature. I don't know why it works with older resolvers. Issue 2800 on stack mentions this. See issue 1575, issue 4087 on Cabal.