Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly allows trailing comments after section headers #9677

Open
tfausak opened this issue Jan 31, 2024 · 1 comment
Open

Incorrectly allows trailing comments after section headers #9677

tfausak opened this issue Jan 31, 2024 · 1 comment

Comments

@tfausak
Copy link
Collaborator

tfausak commented Jan 31, 2024

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.2
name: example
version: 0
build-type: Simple
executable example -- foo
  main-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:

Comments are only allowed on lines on their own. Trailing comments on
other lines are not allowed because they could be confused with program
options.

[ "Double-dash token found."
, "Note: there are no end-of-line comments in .cabal files, only whole line comments."
, "Use \"--\" (quoted double dash) to silence this warning, if you actually want -- token"

@ulysses4ever
Copy link
Collaborator

Good catch! I wonder how many packages use this loophole... Certainly feels like an overlook but can break people if fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants