haskell / haskell/cabal

Stale .hs files generated from .hsc files shadow non-generated .hs files

Open
#3,090 1 comment 0 reactions 0 assignees View on GitHub
Cabal: other type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

I created a minimal example at https://github.com/ntc2/cabal-hsc2hs-bug/tree/2nd-bug and have pasted the README below.

Ran into this while working around https://github.com/haskell/cabal/issues/3087.
## Problem

If you remove `Foo.hsc` and create a new `Foo.hs`, cabal continues to
use the old `Foo.hs` which it generated from the deleted `Foo.hsc`
file. To make cabal use the new `Foo.hs`, you have to delete the old,
cached `Foo.hs` from `dist/*/build`.
## Cabal and GHC versions

```
$ cabal --version
cabal-install version 1.22.6.0
using version 1.22.2.0 of the Cabal library

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.2
```
## Setup

```
$ rm -rf .cabal-sandbox
$ cabal sandbox init
```
## Source files

`bug/Main.hs`:

``` haskell
module Main where

import Foo

main = print foo
```

`bug/Foo.hsc`:

``` haskell
module Foo where

foo = "Using the old .hsc file!"
```

`new-foo/Foo.hs`

``` haskell
module Foo where

foo = "Using the new .hs file!"
```

`cabal-hsc2hs-bug.cabal`:

```
name: cabal-hsc2hs-bug
version: 0.1.0.0
license: BSD3
license-file: LICENSE
author: Nathan Collins
maintainer: nathan.collins@gmail.com
build-type: Simple
cabal-version: >=1.10

executable bug
main-is: Main.hs
other-modules: Foo
hs-source-dirs: bug
build-depends: base
default-language: Haskell2010
```
## Observed, buggy behavior

``` console
$ cabal install && .cabal-sandbox/bin/bug
[...]
"Using the old .hsc file!"
$ rm bug/Foo.hsc
$ cp new-foo/Foo.hs bug/Foo.hs
$ cabal install && .cabal-sandbox/bin/bug
[...]
"Using the old .hsc file!"
$ find dist -name 'Foo.hs' -exec rm {} \;
$ cabal install && .cabal-sandbox/bin/bug
[...]
"Using the new .hs file!"
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the sequence in the linked minimal example using cabal-hsc2hs-bug.cabal, bug/Foo.hsc, and new-foo/Foo.hs. Start by inspecting dist/*/build after removing Foo.hsc and adding Foo.hs. Done means cabal uses the new Foo.hs without manually deleting the cached generated file.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.