Autogenerated modules can accidentally import local modules
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
Autogen modules can throw [GHC-76037](https://errors.haskell.org/messages/GHC-76037/) when there's a local version of a module imported in the generated module.
**To Reproduce**
Steps to reproduce the behavior:
1. Create new cabal project named `cabal_package_imports` with `cabal init`
2. Add module `Data.List` locally containing : `module Data.List where`
3. Add `Data.List` to `exposed-modules
4. Add `Paths_cabal_package_imports` to `autogen-modules`
5. Add `Paths_cabal_package_imports` to `exposed-modules`
6. run `cabal build`
`cabal-package-imports.cabal` contents:
```
cabal-version: 3.0
name: cabal-package-imports
version: 0.1.0.0
license: BSD-2-Clause
license-file: LICENSE
author: John Doe
maintainer: john@doe.com
build-type: Simple
extra-doc-files: CHANGELOG.md
common warnings
ghc-options: -Wall
library
import: warnings
exposed-modules:
MyLib,
Data.List
autogen-modules:
Paths_cabal_package_imports
other-modules:
Paths_cabal_package_imports
build-depends: base ^>=4.20.0.0
hs-source-dirs: src
default-language: GHC2024
```
**Expected behavior**
Cabal can build the library
**Actual behavior**
Cabal fails to build `Paths_cabal_package_imports`
```
lucas@lonneker:~/tmp/cabal_package_imports$ cabal build all
Build profile: -w ghc-9.10.1 -O1
In order, the following will be built (use -v for more details):
- cabal-package-imports-0.1.0.0 (lib) (first run)
Preprocessing library for cabal-package-imports-0.1.0.0...
Building library for cabal-package-imports-0.1.0.0...
[3 of 3] Compiling Paths_cabal_package_imports ( /home/lucas/tmp/cabal_package_imports/dist-newstyle/build/x86_64-linux/ghc-9.10.1/cabal-package-imports-0.1.0.0/build/autogen/Paths_cabal_package_imports.hs, /home/lucas/tmp/cabal_package_imports/dist-newstyle/build/x86_64-linux/ghc-9.10.1/cabal-package-imports-0.1.0.0/build/Paths_cabal_package_imports.o, /home/lucas/tmp/cabal_package_imports/dist-newstyle/build/x86_64-linux/ghc-9.10.1/cabal-package-imports-0.1.0.0/build/Paths_cabal_package_imports.dyn_o )
/home/lucas/tmp/cabal_package_imports/dist-newstyle/build/x86_64-linux/ghc-9.10.1/cabal-package-imports-0.1.0.0/build/autogen/Paths_cabal_package_imports.hs:70:22: error: [GHC-76037]
Not in scope: ‘List.last’
NB: the module ‘Data.List’ does not export ‘last’.
|
70 | | isPathSeparator (List.last dir) = dir ++ fname
| ^^^^^^^^^
Error: [Cabal-7125]
Failed to build cabal-package-imports-0.1.0.0.
```
**System information**
- Operating system :Ubuntu 24.04
- Cabal version: 3.14.2.0
- GHC version: 9.10.1
**Proposed solution**
Use the [PackageImports](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/package_qualified_imports.html) language extension which has been supported since GHC 6.10.1.
I would guess that also solves https://github.com/haskell/cabal/issues/7761
Contributor guide
Assessment
This issue has not been assessed yet.