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

IDE breaks on modules with {-# LANGUAGE CPP #-} #17821

Open
akrmn opened this issue Nov 13, 2023 · 1 comment
Open

IDE breaks on modules with {-# LANGUAGE CPP #-} #17821

akrmn opened this issue Nov 13, 2023 · 1 comment

Comments

@akrmn
Copy link
Contributor

akrmn commented Nov 13, 2023

When opening a daml module that uses the CPP pragma, a red underline will appear at the bottom of the file, and the "Problems" tab will show the error "Main.daml: ❌ 22 in hpp-0.6.4:Hpp.CmdLine CPP". The full error is pasted below:

[{
	"resource": ".../buggy-cpp/daml/Main.daml",
	"owner": "_generated_diagnostic_collection_name_#2",
	"severity": 8,
	"message": "22 in hpp-0.6.4:Hpp.CmdLine\n",
	"source": "CPP",
	"startLineNumber": 105,
	"startColumn": 2147483648,
	"endLineNumber": 105,
	"endColumn": 2147483648
}]

Replicate

To replicate, run the commands below, then open Main.daml in vscode

daml new buggy-cpp

cat << EOF > buggy-cpp/daml/Main.daml
{-# LANGUAGE CPP #-}

module Main where
EOF

cd buggy-cpp; daml studio

Found while working on #17795

@akrmn
Copy link
Contributor Author

akrmn commented Nov 13, 2023

Looking at the source code of hpp (https://github.com/acowley/hpp), one can see that the error on line 105 corresponds to an error call when the argument file does not exist. By overriding the cpp binary used by daml (with --cpp=fake_cpp) with a fake binary that simply logs the given arguments, I found that daml is calling hpp with an argument -iquote/<.../path/to/...>/buggy-cpp/daml/, but looking at the source code of hpp, there's no support for such arguments, so this is interpreted as the target file and thus hpp crashes because clearly there's no such file. Furthermore, using a version of hpp patched to recognize and ignore -iquote arguments, the error message didn't appear (though of course that's not a proper fix). This argument appears to be added by the following line in daml-ghcide,

https://github.com/digital-asset/daml-ghcide/blob/223e571d3cac214d131b85330bf09a1762e88671/src/Development/IDE/Core/Preprocessor.hs#L189

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

No branches or pull requests

1 participant