commercialhaskell / commercialhaskell/stack

Compiler thinks a type is different depending on where it is referenced

Open
#4,786 3 comments 0 reactions 1 assignee Claimed by @mihaimaruseac View on GitHub
component: build further investigation required type: bug
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

I'm unsure where in the chain this is causing problems, whether it's actually an issue with GHC, Cabal, ghc-pkg, or something else, but seems to make sense to start here.

### General summary

Given -
* A stack project with two packages `core` and `testlib`
* `testlib:lib` depends on `core:lib`
* `core:test` depends on `testlib:lib`

The `Foo` type defined in `core:lib` is referenced in `testlib:lib`, providing a gen function and an `Arbitrary` instance. However, the compiler thinks that the `Foo` type defined in `core` and the one referenced in `testlib` are two different types -

```
% stack test
...
• Couldn't match expected type ‘Foo’
with actual type ‘hs-stack-lib-test-conflict-core-0.0.0.0:FooCore.Foo’
NB: ‘hs-stack-lib-test-conflict-core-0.0.0.0:FooCore.Foo’
is defined in ‘FooCore’
in package ‘hs-stack-lib-test-conflict-core-0.0.0.0’
‘Foo’
is defined in ‘FooCore’
in package ‘hs-stack-lib-test-conflict-core-0.0.0.0’
• In the first argument of ‘renderFoo’, namely ‘foo’
In the first argument of ‘(==)’, namely ‘renderFoo foo’
In the expression: renderFoo foo == "foo"
|
6 | main = quickCheck $ forAll genFoo $ \foo -> renderFoo foo == "foo"
| ^^^
```

This is even more confusing since it seems clear that the compiler can actually tell that both types have the same name, are defined in the same module, and come from the same package, but still considers them different types.

### Steps to reproduce

```
% git clone https://github.com/carymrobbins/hs-stack-lib-test-conflict
% cd hs-stack-lib-test-conflict
% stack test
```

### Stack version

```
% stack --version
Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1
```

### Method of installation

Originally with brew on OSX, but have upgraded since via `stack upgrade`.
This also occurs on Arch Linux with stack installed via pacman.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.