You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
main-is: inside two-way if/else: Ambiguous values for modulePath field #9659
executable foo-bar
if flag(wat)
main-is: bar-foo.hs
else
main-is: foo-bar.hs
is rejected with
Ambiguous values for modulePath field: '"bar-foo.hs"' and '"foo-bar.hs"'
CallStack (from HasCallStack):
error, called at src/Distribution/Types/UnqualComponentName.hs:128:7 in Cabal-syntax-3.11.0.0-inplace:Distribution.Types.UnqualComponentName
To Reproduce
$ cat foo.cabal
cabal-version: 3.0
name: foo
version: 0
flag wat
default: False
manual: True
executable foo-bar
if flag(wat)
main-is: bar-foo.hs
else
main-is: foo-bar.hs
hs-source-dirs: src
build-depends: base
$ cabal install
Expected behavior
builds
System information
6.6.12-200.fc39.x86_64 x86_64 GNU/Linux
cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library
ghc-9.6.3
Additional context
with cabal-install 3.10.2.1, the problem can be repaired with indenting else, see. ucsd-progsys/liquidhaskell#2258 (comment) but cabal-install-3.11 will reject that with
Works here, cabal HEAD. Works with your .cabal too.
f@x270:/tmp/prova$ cat prova.cabal
cabal-version: 3.0
name: prova
version: 0.1.0.0
license: NONE
author: Francesco Ariis
maintainer: [email protected]
build-type: Simple
extra-doc-files: CHANGELOG.md
flag wat
common warnings
ghc-options: -Wall
executable prova
import: warnings
if flag(wat)
main-is: bar-foo.hs
else
main-is: foo-bar.hs
build-depends: base ^>=4.18.1.0
hs-source-dirs: app
default-language: Haskell2010
f@x270:/tmp/prova$ tree app/
app/
├── bar-foo.hs
└── foo-bar.hs
1 directory, 2 files
f@x270:/tmp/prova$ cabal check
Warning: this is a debug build of cabal-install with assertions enabled.
These warnings will likely cause trouble when distributing the package:
Warning: [no-category] No 'category' field.
The following errors will cause portability problems on other environments:
Error: [no-syn-desc] No 'synopsis' or 'description' field.
Error: [license-none] The 'license' field is missing or is NONE.
Error: Hackage would reject this package.
f@x270:/tmp/prova$ cabal build
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: The package list for 'hackage.haskell.org' is 33 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-9.6.3 -O1
In order, the following will be built (use -v for more details):
- prova-0.1.0.0 (exe:prova) (first run)
Warning: this is a debug build of cabal-install with assertions enabled.
Configuring executable 'prova' for prova-0.1.0.0...
Warning: this is a debug build of cabal-install with assertions enabled.
Preprocessing executable 'prova' for prova-0.1.0.0...
Building executable 'prova' for prova-0.1.0.0...
[1 of 1] Compiling Main ( app/bar-foo.hs, /tmp/prova/dist-newstyle/build/x86_64-linux/ghc-9.6.3/prova-0.1.0.0/x/prova/build/prova/prova-tmp/Main.o )
[2 of 2] Linking /tmp/prova/dist-newstyle/build/x86_64-linux/ghc-9.6.3/prova-0.1.0.0/x/prova/build/prova/prova
f@x270:/tmp/prova$ cabal --version
cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library
Note, this does not appear to be a check error anymore:
Error: cabal: bar-foo.hsfoo-bar.hs doesn't exist
It looks like both sides of the conditional get evaluated and merged in the install command, not the check command. Maybe we're not evaluating conditionals right in that stanza?
Indeed I mistakenly thought the error was triggered by build/check, but it is not. It is cabal sdist (and cabal install) that fails:
/tmp/cabal-9659 (main)$ cabal --version
cabal-install version 3.11.0.0
compiled using version 3.11.0.0 of the Cabal library
/tmp/cabal-9659 (main)$ cabal sdist
Warning: this is a debug build of cabal-install with assertions enabled.
Ambiguous values for modulePath field: '"bar-foo.hs"' and '"foo-bar.hs"'
CallStack (from HasCallStack):
error, called at src/Distribution/Types/UnqualComponentName.hs:128:7 in Cabal-syntax-3.11.0.0-inplace:Distribution.Types.UnqualComponentName
/tmp/cabal-9659 (main)$ ~/download/cabal --version
cabal-install version 3.10.2.0
compiled using version 3.10.2.1 of the Cabal library
/tmp/cabal-9659 (main)$ ~/download/cabal sdist
Error: cabal: bar-foo.hsfoo-bar.hs doesn't exist
That sounds right. I was going to suggest we use finalizePD instead of flattenPackageDescription but in fact for sdist at least we really do need both sides of the conditional, since we need to add both to the tarball. We just need to ensure that we accumulate as lists of module names, not strings.
I’m getting the same error when running cabal repl Main.hs in the MWE project below. This is the command used by haskell-language-server, which effectively prevents it from working with any project that uses if/else conditionals in the .cabal file.
Activity
ffaf1 commentedon Jan 25, 2024
Works here, cabal HEAD. Works with your
.cabaltoo.jwaldmann commentedon Jan 26, 2024
my reproducer for 3.10.2.0 : https://git.imn.htwk-leipzig.de/waldmann/cabal-9659/-/jobs/39798
gbaz commentedon Jan 26, 2024
Note, this does not appear to be a check error anymore:
It looks like both sides of the conditional get evaluated and merged in the install command, not the check command. Maybe we're not evaluating conditionals right in that stanza?
ffaf1 commentedon Jan 26, 2024
Thanks for providing the reproducer.
Indeed I mistakenly thought the error was triggered by
build/check, but it is not. It iscabal sdist(andcabal install) that fails:Offending code is a broken Semigroup instance:
cabal/Cabal-syntax/src/Distribution/Types/Executable.hs
Lines 40 to 49 in b99a830
b0cb3d4
which I suspect it is getting called via
flattenPackageDescription.gbaz commentedon Jan 26, 2024
That sounds right. I was going to suggest we use
finalizePDinstead offlattenPackageDescriptionbut in fact forsdistat least we really do need both sides of the conditional, since we need to add both to the tarball. We just need to ensure that we accumulate as lists of module names, not strings.ffaf1 commentedon Feb 17, 2024
#9724 provides a possible workaround usingextra-source-file.bravit commentedon Apr 12, 2025
I’m getting the same error when running
cabal repl Main.hsin the MWE project below. This is the command used byhaskell-language-server, which effectively prevents it from working with any project that usesif/elseconditionals in the.cabalfile.MWE:
my-flagged-app.cabal:Main.hs:alt/Main.hs: