haskell / haskell/cabal

Cabal uses source files from `.` even when `.` is not listed under `hs-source-dirs`

Open
#9,235 5 comments 0 reactions 0 assignees View on GitHub
cabal-install: cmd/build type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**To Reproduce**

```
$ tree
.
├── foo.cabal
├── Foo.hs
└── src
└── Foo.hs

2 directories, 3 files
```

```cabal
cabal-version: 3.8
-- foo.cabal
name: foo
version: 0.0.0

library
build-depends: base
hs-source-dirs: src
exposed-modules: Foo
```

```haskell
-- src/Foo.hs
module Foo where

foo :: Int
foo = 23
```

```haskell
-- Foo.hs
module Foo where

foo :: Int
foo = "bar"
```

```
$ cabal build

Foo.hs:4:7: error: [GHC-83865]
• Couldn't match type ‘[Char]’ with ‘Int’
Expected: Int
Actual: String
• In the expression: "bar"
In an equation for ‘foo’: foo = "bar"
|
4 | foo = "bar"
| ^^^^^
Error: cabal: Failed to build foo-0.0.0.
```

**Expected behavior**
`cabal build` succeeds.

**System information**
- cabal 3.10.1.0 / ghc 9.6.2 / Linux

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with foo.cabal, Foo.hs, and src/Foo.hs, then run cabal build. Trace Cabal's source-file discovery and hs-source-dirs handling to determine why the root Foo.hs is compiled. Done means the example builds successfully while using only the declared src directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.