CPP errors with absolute paths on Windows don't get proper error messages
Summary
Given a CPP file with an error, e.g. Foo.hs
:
{-# LANGUAGE CPP #-}
module Testing where
#ifdef FOO
foo = 42
If I run Foo.hs
it's fine, if I give an absolute path of C:\Neil\Foo.hs
then the error isn't properly captured or reported.
Steps to reproduce
Given the above file I run:
c:\Neil>runhaskell Foo.hs
Foo.hs:3:0: error:
error: unterminated #ifdef
#ifdef FOO
|
3 | #ifdef FOO
| ^
`gcc.exe' failed in phase `C pre-processor'. (Exit code: 1)
c:\Neil>runhaskell C:\Neil\Foo.hs
C:\\Neil\\Foo.hs:3:0: error: unterminated #ifdef
#ifdef FOO
`gcc.exe' failed in phase `C pre-processor'. (Exit code: 1)
Expected behavior
I would expect both to give the same pretty error message, and importantly, raise the right exceptions internally. The fact the right exception is not thrown means that Ghcide which uses absolute paths and the GHC API doesn't get the right exceptions on Windows. We are tracking this bug in https://github.com/digital-asset/ghcide/issues/402.
Environment
- GHC version used: 8.8.2
Optional:
- Operating System: Windows
Diagnosis
I'm pretty sure the bug is when you have a drive letter containing a :
. The code in https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/main/SysTools/Process.hs#L307-323 seems dodgy, as the error message:
C:\\Neil\\Foo.hs:3:0: error: unterminated #ifdef
Is first split into C
as the filename and \\Neil...
as an Int
, which it isn't, and thus the parsing of the error message fails.