Skip to content

Commit

Permalink
Add tests for more GHC errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jan 26, 2025
1 parent 6a0d7b2 commit 8a8f678
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
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

0 comments on commit 8a8f678

Please sign in to comment.