summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Utils/Monad.hs
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-04-12 14:21:20 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-19 23:32:27 -0400
commitc8564c639a9889d4d19c68f4b96c092f670b092c (patch)
tree166c45dfb023a5414160a378e04e0170c029bd07 /compiler/GHC/Tc/Utils/Monad.hs
parentbaa969c39b511cad42ac4f806205fffffe201f5b (diff)
downloadhaskell-c8564c639a9889d4d19c68f4b96c092f670b092c.tar.gz
Add some TcRn diagnostic messages
This commit converts some TcRn diagnostic into proper structured errors. Ported by this commit: * Add TcRnImplicitLift This commit adds the TcRnImplicitLift diagnostic message and a prototype API to be able to log messages which requires additional err info. * Add TcRnUnusedPatternBinds * Add TcRnDodgyExports * Add TcRnDodgyImports message * Add TcRnMissingImportList
Diffstat (limited to 'compiler/GHC/Tc/Utils/Monad.hs')
-rw-r--r--compiler/GHC/Tc/Utils/Monad.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/compiler/GHC/Tc/Utils/Monad.hs b/compiler/GHC/Tc/Utils/Monad.hs
index f1a5425b6f..730e666a2a 100644
--- a/compiler/GHC/Tc/Utils/Monad.hs
+++ b/compiler/GHC/Tc/Utils/Monad.hs
@@ -92,7 +92,7 @@ module GHC.Tc.Utils.Monad(
failWithTc, failWithTcM,
checkTc, checkTcM,
failIfTc, failIfTcM,
- warnIfFlag, warnIf, diagnosticTc, diagnosticTcM,
+ warnIfFlag, warnIf, diagnosticTc, diagnosticTcM, addDetailedDiagnostic, addTcRnDiagnostic,
addDiagnosticTc, addDiagnosticTcM, addDiagnostic, addDiagnosticAt, add_diagnostic,
mkErrInfo,
@@ -1548,6 +1548,25 @@ addDiagnosticTcM reason (env0, msg)
addDiagnostic :: DiagnosticReason -> SDoc -> TcRn ()
addDiagnostic reason msg = add_diagnostic reason msg Outputable.empty
+-- | A variation of 'addDiagnostic' that takes a function to produce a 'TcRnDsMessage'
+-- given some additional context about the diagnostic.
+addDetailedDiagnostic :: (ErrInfo -> TcRnMessage) -> TcM ()
+addDetailedDiagnostic mkMsg = do
+ loc <- getSrcSpanM
+ printer <- getPrintUnqualified
+ dflags <- getDynFlags
+ env0 <- tcInitTidyEnv
+ ctxt <- getErrCtxt
+ err_info <- mkErrInfo env0 ctxt
+ reportDiagnostic (mkMsgEnvelope dflags loc printer (mkMsg (ErrInfo err_info)))
+
+addTcRnDiagnostic :: TcRnMessage -> TcM ()
+addTcRnDiagnostic msg = do
+ loc <- getSrcSpanM
+ printer <- getPrintUnqualified
+ dflags <- getDynFlags
+ reportDiagnostic (mkMsgEnvelope dflags loc printer msg)
+
-- | Display a diagnostic for a given source location.
addDiagnosticAt :: DiagnosticReason -> SrcSpan -> SDoc -> TcRn ()
addDiagnosticAt reason loc msg = add_diagnostic_at reason loc msg Outputable.empty