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

Add tests for more GHC errors #152

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/GHC/Diagnostic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ format diagnostic = encodeUtf8 . render $ unlines [
unlines = foldr ($+$) empty

removeGhciSpecificHints :: Diagnostic -> Diagnostic
removeGhciSpecificHints diagnostic = diagnostic { hints = map f diagnostic.hints }
removeGhciSpecificHints diagnostic = diagnostic { hints = map processHint diagnostic.hints }
where
f :: String -> String
f input = case lines input of
[hint, "You may enable this language extension in GHCi with:", ghciHint] | " :set -X" `isPrefixOf` ghciHint -> hint
isSetLanguageExtension :: String -> Bool
isSetLanguageExtension = isPrefixOf " :set -X"

processHint :: String -> String
processHint input = case lines input of
[hint, "You may enable this language extension in GHCi with:", ghciHint]
| isSetLanguageExtension ghciHint -> hint
hint : "You may enable these language extensions in GHCi with:" : ghciHints
| all isSetLanguageExtension ghciHints -> hint
_ -> input
1 change: 1 addition & 0 deletions test/GHC/DiagnosticSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ spec = do
test "variable-not-in-scope"
test "variable-not-in-scope-perhaps-use"
test "use-BlockArguments"
test "use-TemplateHaskellQuotes"
test "non-existing"
test "parse-error"
test "lex-error"
Expand Down
2 changes: 1 addition & 1 deletion test/assets/use-BlockArguments/Foo.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE NoBlockArguments #-}
module BlockArguments.Foo where
module Foo where

foo :: IO ()
foo = id do return ()
2 changes: 2 additions & 0 deletions test/assets/use-TemplateHaskellQuotes/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Foo where
foo = [|23|]
1 change: 1 addition & 0 deletions test/assets/use-TemplateHaskellQuotes/err.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"1.0","ghcVersion":"ghc-9.10.1","span":{"file":"test/assets/use-TemplateHaskellQuotes/Foo.hs","start":{"line":2,"column":7},"end":{"line":2,"column":13}},"severity":"Error","code":62558,"message":["Syntax error on [| 23 |]","In the Template Haskell quotation [| 23 |]"],"hints":["Enable any of the following extensions: TemplateHaskell, TemplateHaskellQuotes\nYou may enable these language extensions in GHCi with:\n :set -XTemplateHaskell\n :set -XTemplateHaskellQuotes"]}
6 changes: 6 additions & 0 deletions test/assets/use-TemplateHaskellQuotes/err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test/assets/use-TemplateHaskellQuotes/Foo.hs:2:7: error: [GHC-62558]
• Syntax error on [| 23 |]
• In the Template Haskell quotation [| 23 |]
Suggested fix:
Enable any of the following extensions: TemplateHaskell, TemplateHaskellQuotes

Loading