summaryrefslogtreecommitdiff
path: root/compiler/GHC/Parser/Lexer.x
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-04-20 11:03:01 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-20 18:08:37 -0400
commitaac87bd388547e28aca1c19e7436ff5fa9245f04 (patch)
tree3c03ec7ad5336d45c4108483df0a2f5bce70de1f /compiler/GHC/Parser/Lexer.x
parent7c066734705048edb5b5b0afc30acea0805ec18d (diff)
downloadhaskell-aac87bd388547e28aca1c19e7436ff5fa9245f04.tar.gz
Extensible Hints for diagnostic messages
This commit extends the GHC diagnostic hierarchy with a `GhcHint` type, modelling helpful suggestions emitted by GHC which can be used to deal with a particular warning or error. As a direct consequence of this, the `Diagnostic` typeclass has been extended with a `diagnosticHints` method, which returns a `[GhcHint]`. This means that now we can clearly separate out the printing of the diagnostic message with the suggested fixes. This is done by extending the `printMessages` function in `GHC.Driver.Errors`. On top of that, the old `PsHint` type has been superseded by the new `GhcHint` type, which de-duplicates some hints in favour of a general `SuggestExtension` constructor that takes a `GHC.LanguageExtensions.Extension`.
Diffstat (limited to 'compiler/GHC/Parser/Lexer.x')
-rw-r--r--compiler/GHC/Parser/Lexer.x9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x
index 2864e2998e..dc13d44493 100644
--- a/compiler/GHC/Parser/Lexer.x
+++ b/compiler/GHC/Parser/Lexer.x
@@ -109,6 +109,7 @@ import GHC.Data.Maybe
import GHC.Data.OrdList
import GHC.Utils.Misc ( readSignificandExponentPair, readHexSignificandExponentPair )
+import GHC.Types.Error ( GhcHint(..) )
import GHC.Types.SrcLoc
import GHC.Types.SourceText
import GHC.Types.Basic ( InlineSpec(..), RuleMatchInfo(..))
@@ -3044,11 +3045,11 @@ srcParseErr options buf len loc = PsError (PsErrParse token) suggests loc
ps_enabled = PatternSynonymsBit `xtest` pExtsBitmap options
sug c s = if c then Just s else Nothing
- sug_th = sug (not th_enabled && token == "$") SuggestTH -- #7396
- sug_rdo = sug (token == "<-" && mdoInLast100) SuggestRecursiveDo
- sug_do = sug (token == "<-" && not mdoInLast100) SuggestDo
+ sug_th = sug (not th_enabled && token == "$") (SuggestExtension LangExt.TemplateHaskell) -- #7396
+ sug_rdo = sug (token == "<-" && mdoInLast100) (SuggestExtension LangExt.RecursiveDo)
+ sug_do = sug (token == "<-" && not mdoInLast100) SuggestMissingDo
sug_let = sug (token == "=" && doInLast100) SuggestLetInDo -- #15849
- sug_pat = sug (not ps_enabled && pattern_ == "pattern ") SuggestPatternSynonyms -- #12429
+ sug_pat = sug (not ps_enabled && pattern_ == "pattern ") (SuggestExtension LangExt.PatternSynonyms) -- #12429
suggests
| null token = []
| otherwise = catMaybes [sug_th, sug_rdo, sug_do, sug_let, sug_pat]