haskell / haskell/cabal

Additional flag settings are ignored if the original ones are in a conditional block

Open
#9,293 7 comments 3 reactions 1 assignee Claimed by @zlonast View on GitHub
attention: pr-welcome can-workaround re: conditional re: flag re: project-file type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**
This is a weird one. What I'm observing is that this:
```
package foo
flags: +bar

package foo
flags: -bar
```
builds `foo` with `bar` disabled (correct), but that this:

```
-- Assume we're using GHC > 9 so this conditional is satisfied
if impl(ghc>9)
package foo
flags: +bar

pacakge foo
flags: -bar
```
builds `foo` with `bar` _enabled_ (incorrect).

**To Reproduce**

- Checkout https://github.com/haskell/lsp/tree/mpj/cabal-bug
- `cabal build lsp` (with GHC > 9 so the conditional is satisfied)
- Observe that cabal declares that it is going to build `exe:lsp-demo-simple-server`
- Remove the conditional around the flag setting in `cabal.project`
- `cabal build lsp`
- Observe that cabal does not declare that it is going to build `exe:lsp-demo-simple-server`

**Expected behavior**

The second flag setting should override the first regardless of whether the first one is conditional.

**System information**
- NixOS
- `cabal-3.10.1.01
- `ghc-9.2.7`

**Additional context**

I don't think this is https://github.com/haskell/cabal/issues/8699, because:
1. I can reproduce it even if I wipe out `dist-newstyle` before building; and
2. The problem is not the _conditional_ section being ignored, but rather the later _unconditional_ section being ignored.

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.