After interpol preprocessing, there's a single LINE 1 pragma at the top of the file, but no others, even though comments are stripped and whitespace is changed. This leads to GHC's error messages pointing at wrong lines. Consider for example:
-- Hello!
{-# OPTIONS_GHC -F -pgmF interpol #-}
-- Hey there!
module Bug where
-- Greetings!
foo :: Int
foo = "wrong type"
-- Bye!
After ghc -E, we're left with:
{-# LINE 1 "asdf.hs" #-}
{-# OPTIONS_GHC -F -pgmF interpol #-}
module Bug where
foo :: Int
foo = "wrong type"
And the error message points to asdf.hs:5:7 instead of asdf.hs:14:7. If foo here were to contain a string interpolation, it'd point to line 6 instead of 5, as the import of Text.Interpol would be added.
The Test/NoWarn.hs file in the repository is another example of a file that would suffer from this, if it were to contain any type errors. (For example, try removing putStrLn from the definition of foo there.)
I'm not sure what can be done about this as I'm not at all familiar with haskell-src-exts. In my mind, the simplest solution would be to not modify the original source in any way except to perform the string interpolation (duh), add the import, and immediately after the import add a LINE pragma for the appropriate line number. If that's not an option, you need a LINE pragma after every removed comment and blank line...
After interpol preprocessing, there's a single
LINE 1pragma at the top of the file, but no others, even though comments are stripped and whitespace is changed. This leads to GHC's error messages pointing at wrong lines. Consider for example:After
ghc -E, we're left with:{-# LINE 1 "asdf.hs" #-} {-# OPTIONS_GHC -F -pgmF interpol #-} module Bug where foo :: Int foo = "wrong type"And the error message points to
asdf.hs:5:7instead ofasdf.hs:14:7. Iffoohere were to contain a string interpolation, it'd point to line 6 instead of 5, as the import ofText.Interpolwould be added.The
Test/NoWarn.hsfile in the repository is another example of a file that would suffer from this, if it were to contain any type errors. (For example, try removingputStrLnfrom the definition offoothere.)I'm not sure what can be done about this as I'm not at all familiar with haskell-src-exts. In my mind, the simplest solution would be to not modify the original source in any way except to perform the string interpolation (duh), add the import, and immediately after the import add a
LINEpragma for the appropriate line number. If that's not an option, you need aLINEpragma after every removed comment and blank line...