haskell / haskell/cabal

`cabal init` incorrectly writes non-ASCII file names in `library:exposed-modules`

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

Description

**Describe the bug**
Consider a folder hierarchy that looks like

```
proglet/
|- Typeclass/
|- Pokémon.hs
```

Running `cabal init --interactive` when the working directory is `proglet` generates the files necessary for `cabal v2-build`.

Running `cabal v2-build`, however, gives the unexpected error

```
Typeclass/Pokémon.hs:1:8: error:
File name does not match module name:
Saw: ‘Typeclass.Pokémon’
Expected: ‘Typeclass.Pokémon’
|
1 | module Typeclass.Pokémon where
| ^^^^^^^^^^^^^^^^^
```

**To Reproduce**
1. Create folder `proglet`
2. Create folder `proglet/Typeclass`
3. Create file `proglet/Typeclass/Pokémon.hs` with content

```
module Typeclass.Pokémon where

x = 1
```

4. Change the working directory to `proglet`
5. Run `cabal init --interactive` and complete the prompts this way
- Don't generate a "simple project with sensible defaults"
- Build a library
- Use any version of the Cabal specification
- Any package name of your choosing
- Any package version
- Any license
- Any author name
- Any email
- Any project URL
- Any synopsis
- Any category
- No source directory
- No test suite
- Haskell2010
- No "informative comments"
6. Run `cabal v2-build` and observe the error

**Expected behavior**
I expected the build to succeed.

**System information**
- Operating system: macOS 10.14
- `cabal` version: 3.0.0.0
- `ghc` version: 8.6.5

**Additional context**
It seems that the "e with acute accent" under "Saw" is the UTF-8 character U+00E9, while the "e with acute accent" under "Expected" is a combination of the normal letter "e" (U+0065) and some acute accent character.

Since the "e with acute accent" under "Expected" corresponds to the contents of the `library:exposed-modules` section of the `.cabal` file, I checked `proglet.cabal` (I have removed the comment lines below).

```
cabal-version: 2.4

name: proglet
version: 0.1.0.0
license: BSD-3-Clause
license-file: LICENSE
author: Fyrbll
maintainer: unnecessary
extra-source-files: CHANGELOG.md

library
exposed-modules: Typeclass.Pokémon
build-depends: base ^>=4.12.0.0
default-language: Haskell2010
```

I changed `Typeclass.Pokémon` in the file above to `Typeclass.Pokémon`, where the latter actually uses U+00E9, and then `cabal build` worked painlessly.

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.