[solved] `cabal repl` ignores `default-language` and `default-extensions`

The problem as text

My understanding is that NumericUnderscores is part of the GHC2021 language spec. And yet even if my cabal file sets the default-language to GHC2021 and includes NumericUnderscores in default-extensions, cabal repl won’t load a module that uses an underscore in a number.

Worse, I can include a nonsense extension in default-extensions and cabal doesn’t seem to notice it.

I’m using NixOS and cabal 3.8.1.0.

The problem as a shell transcript

[jeff@jbb-hp17:~/code/music/montevideo]$ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library

[jeff@jbb-hp17:~/code/music/montevideo]$ grep default-extensions mtv.cabal  -A 2
  default-extensions:
    NumericUnderscores
    , A_Nonexistent_Extension
  default-language: GHC2021

[jeff@jbb-hp17:~/code/music/montevideo]$ cabal repl
...
Montevideo/Types.hs:10:5: error:
    Use NumericUnderscores to allow underscores in integer literals
   |
10 | x = 123_456
   |     ^^^^^^^
Failed, 16 modules loaded.
ghci>
2 Likes

Works here:

f@mkiii:~/download/repl$ cat ropl.cabal
cabal-version:   3.0
name:            ropl
version:         0.1.0.0
license:         BSD-3-Clause
license-file:    LICENSE
author:          Francesco Ariis
maintainer:      fa-ml@ariis.it
build-type:      Simple
extra-doc-files: CHANGELOG.md

common warnings
    ghc-options: -Wall

executable ropl
    import:           warnings
    main-is:          Main.hs
    build-depends:    base ^>=4.16.0.0
    hs-source-dirs:   app
    default-language: Haskell2010
    default-extensions: NumericUnderscores
f@mkiii:~/download/repl$ cabal repl
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
 - ropl-0.1.0.0 (exe:ropl) (cannot read state cache)
Configuring executable 'ropl' for ropl-0.1.0.0..
Preprocessing executable 'ropl' for ropl-0.1.0.0..
GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/f/cfg/dot-files/ghci
[1 of 1] Compiling Main             ( app/Main.hs, interpreted )
Ok, one module loaded.
λ> 123_456 :: Int
123456
λ> :quit
Leaving GHCi.
f@mkiii:~/download/repl$ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library
f@mkiii:~/download/repl$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.1
1 Like

Same for the bogus extension:

f@mkiii:~/download/repl$ cabal-old repl
Resolving dependencies...
Error: cabal-old: Could not resolve dependencies:
[__0] next goal: ropl (user goal)
[__0] rejecting: ropl-0.1.0.0 (conflict: requires unknown extension
NonExistantExt; did you mean NoGADTSyntax?)
[__0] fail (backjumping, conflict set: ropl)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: ropl

Care to share an MRE?

edit: note to my future self, see #8539.

2 Likes

Solved, thanks!

Your MRE idea was good. When I started a fresh project it was given a cabal-version: 3.4 field (which was absent in the code that was giving me the problem, presumably because I began that code in a much earlier version of Cabal). The fresh project did not have the issue.

So I went back to the old code, added a cabal-version: 3.8 line at the start (not sure if that does anything different from one that says 3.4), updated the license: field to match the new syntax, and the problem was solved.

3 Likes