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.hs18
-rw-r--r--compiler/GHC/Parser/Header.hs5
3 files changed, 35 insertions, 5 deletions
diff --git a/compiler/GHC/Parser/Errors/Ppr.hs b/compiler/GHC/Parser/Errors/Ppr.hs
index 2a238190c9..1d34129474 100644
--- a/compiler/GHC/Parser/Errors/Ppr.hs
+++ b/compiler/GHC/Parser/Errors/Ppr.hs
@@ -472,7 +472,7 @@ instance Diagnostic PsMessage where
diagnosticReason = \case
PsUnknownMessage m -> diagnosticReason m
- PsHeaderMessage _ -> ErrorWithoutFlag
+ PsHeaderMessage m -> psHeaderMessageReason m
PsWarnTab{} -> WarningWithFlag Opt_WarnTabs
PsWarnTransitionalLayout{} -> WarningWithFlag Opt_WarnAlternativeLayoutRuleTransitional
PsWarnOperatorWhitespaceExtConflict{} -> WarningWithFlag Opt_WarnOperatorWhitespaceExtConflict
@@ -754,6 +754,19 @@ psHeaderMessageDiagnostic = \case
, text "Expecting whitespace-separated list of GHC options."
, text " E.g. {-# OPTIONS_GHC -Wall -O2 #-}"
, text ("Input was: " ++ show str) ]
+ PsErrUnknownOptionsPragma flag
+ -> mkSimpleDecorated $ text "Unknown flag in {-# OPTIONS_GHC #-} pragma:" <+> text flag
+
+psHeaderMessageReason :: PsHeaderMessage -> DiagnosticReason
+psHeaderMessageReason = \case
+ PsErrParseLanguagePragma
+ -> ErrorWithoutFlag
+ PsErrUnsupportedExt{}
+ -> ErrorWithoutFlag
+ PsErrParseOptionsPragma{}
+ -> ErrorWithoutFlag
+ PsErrUnknownOptionsPragma{}
+ -> ErrorWithoutFlag
psHeaderMessageHints :: PsHeaderMessage -> [GhcHint]
psHeaderMessageHints = \case
@@ -771,6 +784,8 @@ psHeaderMessageHints = \case
suggestions = fuzzyMatch unsup supported
PsErrParseOptionsPragma{}
-> noHints
+ PsErrUnknownOptionsPragma{}
+ -> noHints
suggestParensAndBlockArgs :: [GhcHint]
diff --git a/compiler/GHC/Parser/Errors/Types.hs b/compiler/GHC/Parser/Errors/Types.hs
index a78685c11a..8f1df7308e 100644
--- a/compiler/GHC/Parser/Errors/Types.hs
+++ b/compiler/GHC/Parser/Errors/Types.hs
@@ -40,6 +40,24 @@ data PsHeaderMessage
| PsErrUnsupportedExt !String ![String]
| PsErrParseOptionsPragma !String
+ {-| PsErrUnsupportedOptionsPragma is an error that occurs when an unknown
+ OPTIONS_GHC pragma is supplied is found.
+
+ Example(s):
+ {-# OPTIONS_GHC foo #-}
+
+ Test case(s):
+
+ tests/safeHaskell/flags/SafeFlags28
+ tests/safeHaskell/flags/SafeFlags19
+ tests/safeHaskell/flags/SafeFlags29
+ tests/parser/should_fail/T19923c
+ tests/parser/should_fail/T19923b
+ tests/parser/should_fail/readFail044
+ tests/driver/T2499
+ -}
+ | PsErrUnknownOptionsPragma !String
+
data PsMessage
=
diff --git a/compiler/GHC/Parser/Header.hs b/compiler/GHC/Parser/Header.hs
index 68468d89eb..1199d64957 100644
--- a/compiler/GHC/Parser/Header.hs
+++ b/compiler/GHC/Parser/Header.hs
@@ -39,7 +39,6 @@ import GHC.Types.SourceError
import GHC.Types.SourceText
import GHC.Utils.Misc
-import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import GHC.Utils.Monad
import GHC.Utils.Error
@@ -422,9 +421,7 @@ checkProcessArgsResult flags
liftIO $ throwErrors $ foldMap (singleMessage . mkMsg) flags
where mkMsg (L loc flag)
= mkPlainErrorMsgEnvelope loc $
- GhcDriverMessage $ DriverUnknownMessage $ mkPlainError noHints $
- text "unknown flag in {-# OPTIONS_GHC #-} pragma:" <+>
- text flag
+ GhcPsMessage $ PsHeaderMessage $ PsErrUnknownOptionsPragma flag
-----------------------------------------------------------------------------