summaryrefslogtreecommitdiff
path: root/compiler/GHC/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Parser')
-rw-r--r--compiler/GHC/Parser/Errors/Ppr.hs17
-rw-r--r--compiler/GHC/Parser/Errors/Types.hs10
2 files changed, 27 insertions, 0 deletions
diff --git a/compiler/GHC/Parser/Errors/Ppr.hs b/compiler/GHC/Parser/Errors/Ppr.hs
index 9396961cab..138a24ccd5 100644
--- a/compiler/GHC/Parser/Errors/Ppr.hs
+++ b/compiler/GHC/Parser/Errors/Ppr.hs
@@ -28,6 +28,7 @@ import GHC.Hs.Type (pprLHsContext)
import GHC.Builtin.Names (allNameStrings)
import GHC.Builtin.Types (filterCTuple)
import qualified GHC.LanguageExtensions as LangExt
+import Data.List.NonEmpty (NonEmpty((:|)))
instance Diagnostic PsMessage where
@@ -44,6 +45,20 @@ instance Diagnostic PsMessage where
-> mkSimpleDecorated $
text "Multiple Haddock comments for a single entity are not allowed." $$
text "The extraneous comment will be ignored."
+ PsWarnBidirectionalFormatChars ((loc,_,desc) :| xs)
+ -> mkSimpleDecorated $
+ text "A unicode bidirectional formatting character" <+> parens (text desc)
+ $$ text "was found at offset" <+> ppr (bufPos (psBufPos loc)) <+> text "in the file"
+ $$ (case xs of
+ [] -> empty
+ xs -> text "along with further bidirectional formatting characters at" <+> pprChars xs
+ where
+ pprChars [] = empty
+ pprChars ((loc,_,desc):xs) = text "offset" <+> ppr (bufPos (psBufPos loc)) <> text ":" <+> text desc
+ $$ pprChars xs
+ )
+ $$ text "Bidirectional formatting characters may be rendered misleadingly in certain editors"
+
PsWarnTab tc
-> mkSimpleDecorated $
text "Tab character found here"
@@ -474,6 +489,7 @@ instance Diagnostic PsMessage where
diagnosticReason = \case
PsUnknownMessage m -> diagnosticReason m
PsHeaderMessage m -> psHeaderMessageReason m
+ PsWarnBidirectionalFormatChars{} -> WarningWithFlag Opt_WarnUnicodeBidirectionalFormatCharacters
PsWarnTab{} -> WarningWithFlag Opt_WarnTabs
PsWarnTransitionalLayout{} -> WarningWithFlag Opt_WarnAlternativeLayoutRuleTransitional
PsWarnOperatorWhitespaceExtConflict{} -> WarningWithFlag Opt_WarnOperatorWhitespaceExtConflict
@@ -586,6 +602,7 @@ instance Diagnostic PsMessage where
diagnosticHints = \case
PsUnknownMessage m -> diagnosticHints m
PsHeaderMessage m -> psHeaderMessageHints m
+ PsWarnBidirectionalFormatChars{} -> noHints
PsWarnTab{} -> [SuggestUseSpaces]
PsWarnTransitionalLayout{} -> noHints
PsWarnOperatorWhitespaceExtConflict sym -> [SuggestUseWhitespaceAfter sym]
diff --git a/compiler/GHC/Parser/Errors/Types.hs b/compiler/GHC/Parser/Errors/Types.hs
index 181f793741..d39048c441 100644
--- a/compiler/GHC/Parser/Errors/Types.hs
+++ b/compiler/GHC/Parser/Errors/Types.hs
@@ -16,6 +16,8 @@ import GHC.Types.Name.Occurrence (OccName)
import GHC.Types.Name.Reader
import GHC.Unit.Module.Name
import GHC.Utils.Outputable
+import Data.List.NonEmpty (NonEmpty)
+import GHC.Types.SrcLoc (PsLoc)
-- The type aliases below are useful to make some type signatures a bit more
-- descriptive, like 'handleWarningsThrowErrors' in 'GHC.Driver.Main'.
@@ -72,6 +74,14 @@ data PsMessage
-}
| PsHeaderMessage !PsHeaderMessage
+ {-| PsWarnBidirectionalFormatChars is a warning (controlled by the -Wwarn-bidirectional-format-characters flag)
+ that occurs when unicode bi-directional format characters are found within in a file
+
+ The 'PsLoc' contains the exact position in the buffer the character occured, and the
+ string contains a description of the character.
+ -}
+ | PsWarnBidirectionalFormatChars (NonEmpty (PsLoc, Char, String))
+
{-| PsWarnTab is a warning (controlled by the -Wwarn-tabs flag) that occurs
when tabulations (tabs) are found within a file.