haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Incorrect diagnostics in the presence of TemplateHaskell + Safe

Open Ptival opened this issue 1 year ago • 1 comments

I recently run into a confusing situation where under VSCode/HLS, I got the following error message:

error:
• Top-level splices are not permitted without TemplateHaskell
• In the untyped splice: $(quoteExp there "lib/Cryptol.cry")

in a file that contained the line {-# LANGUAGE TemplateHaskell #-}.

After a certain time being confused, I actually ran GHC, and its output made the situation much clearer:

warning:
    -XTemplateHaskell is not allowed in Safe Haskell; ignoring -XTemplateHaskell
   |
15 | {-# LANGUAGE TemplateHaskell #-}
   |              ^^^^^^^^^^^^^^^

It turns out the same file also contained the line {-# LANGUAGE Safe #-}!

However, this warning is not reported in VSCode. While I find this particular instance quite egregious (I may bring it up to the GHC bug tracker), in general I'm not sure under what conditions warnings make it into VSCode via HLS. I'm just raising this here as a heads up, I'm not sure who is responsible for this, and what can be done in HLS proper.

To reproduce, a simple file like:

{-# LANGUAGE Safe #-}
{-# LANGUAGE TemplateHaskell #-}
test = $(1)

should suffice.

Ptival avatar Jan 23 '24 21:01 Ptival

I think this is likely to be the specific combination of things. We do slightly alter the set of flags we get from the user, which occasionally results in issues like this. I wouldn't be shocked if we turn off Safe or something. So I'll mark this as a more specific issue.

michaelpj avatar Jan 24 '24 10:01 michaelpj