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
Describe the bug
Typically Cabal does not allow trailing comments. All comments must be on their own line. They cannot follow a field name or value. However if you put an trailing comment after a section header, it is accepted by Cabal.
To Reproduce
Create a package description like this:
cabal-version: >=1.2name: example
version: 0build-type: Simple
executableexample-- foomain-is: Main.hs
build-depends: base
The only important line is executable example -- foo. Using executable specifically isn't necessary. Any section (like library) behaves the same. I used executable to show that the comment isn't being interpreted as an argument to the section. In other words, we're not defining an executable called "example -- foo".
Similarly the cabal-version does not appear to be important. Setting it to, say, cabal-version: 3.8 exhibits the same behavior.
To let Cabal build this example package successfully, also create a Main.hs file. It's not important what's in it. Something like this will work:
main =pure()
Finally, run cabal build.
Expected behavior
The build should fail due to invalid syntax in the package description. For example, consider the following package description:
name: example -- foo
That fails with the following error:
Errors encountered when parsing cabal file ./example.cabal:
example.cabal:1:15: error:
unexpected '-'
expecting space or end of input
1 | name: example -- foo
| ^
System information
$ cabal --version
cabal-install version 3.10.2.1
compiled using version 3.10.2.1 of the Cabal library
Additional context
It seems like either trailing comments should be allowed everywhere or prohibited everywhere. I think the intent is for them to be prohibited. Various pieces of documentation and code say that:
Describe the bug
Typically Cabal does not allow trailing comments. All comments must be on their own line. They cannot follow a field name or value. However if you put an trailing comment after a section header, it is accepted by Cabal.
To Reproduce
Create a package description like this:
The only important line is
executable example -- foo
. Usingexecutable
specifically isn't necessary. Any section (likelibrary
) behaves the same. I usedexecutable
to show that the comment isn't being interpreted as an argument to the section. In other words, we're not defining an executable called"example -- foo"
.Similarly the
cabal-version
does not appear to be important. Setting it to, say,cabal-version: 3.8
exhibits the same behavior.To let Cabal build this example package successfully, also create a
Main.hs
file. It's not important what's in it. Something like this will work:Finally, run
cabal build
.Expected behavior
The build should fail due to invalid syntax in the package description. For example, consider the following package description:
That fails with the following error:
System information
Additional context
It seems like either trailing comments should be allowed everywhere or prohibited everywhere. I think the intent is for them to be prohibited. Various pieces of documentation and code say that:
cabal/doc/how-to-package-haskell-code.rst
Lines 140 to 142 in 46a7bfc
cabal/Cabal-syntax/src/Distribution/Parsec.hs
Lines 276 to 278 in 46a7bfc
The text was updated successfully, but these errors were encountered: