summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorAlfredo Di Napoli <alfredo@well-typed.com>2021-07-27 09:45:27 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-28 13:20:52 -0400
commit4a2ef3dd38adf613f425bb1ef8a8614bea558ff0 (patch)
tree3e7173fa8426e4bd70997ae160966b3e362f2572 /compiler
parent3382b3d6f9a818d0afe62112dd368ae04778d16e (diff)
downloadhaskell-4a2ef3dd38adf613f425bb1ef8a8614bea558ff0.tar.gz
Port more DriverUnknownMessage into richer DriverMessage constructors
In order: * Introduce the `PsErrUnknownOptionsPragma` diagnostic message This commit changes the diagnostic emitted inside `GHC.Parser.Header.checkProcessArgsResult` from an (erroneous) and unstructured `DriverUnknownMessage` to a `PsErrUnknownOPtionsPragma`, i.e. a new data constructor of a `PsHeaderMessage`. * Add the `DriverUserDefinedRuleIgnored` diagnostic message * Add `DriverUserDefinedRuleIgnored` data constructor This commit adds (and use) a new data constructor to the `DriverMessage` type, replacing a `DriverUnknownMessage` with it. * Add and use `DriverCannotLoadInterfaceFile` constructor This commit introduces the DriverCannotLoadInterfaceFile constructor for the `DriverMessage` type and it uses it to replace and occurrence of `DriverUnknownMessage`. * Add and use the `DriverInferredSafeImport` constructor This commit adds a new `DriverInferredSafeImport` constructor to the `DriverMessage` type, and uses it in `GHC.Driver.Main` to replace one occurrence of `DriverUnknownMessage`. * Add and use `DriverCannotImportUnsafeModule` constructor This commit adds the `DriverCannotImportUnsafeModule` constructor to the `DriverMessage` type, and later using it to replace one usage of `DriverUnknownMessage` in the `GHC.Driver.Main` module. * Add and use `DriverMissingSafeHaskellMode` constructor * Add and use `DriverPackageNotTrusted` constructor * Introduce and use `DriverInferredSafeModule` constructor * Add and use `DriverMarkedTrustworthyButInferredSafe` constructor * Add and use `DriverCannotImportFromUntrustedPackage`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Driver/Errors/Ppr.hs90
-rw-r--r--compiler/GHC/Driver/Errors/Types.hs138
-rw-r--r--compiler/GHC/Driver/Main.hs65
-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
6 files changed, 274 insertions, 59 deletions
diff --git a/compiler/GHC/Driver/Errors/Ppr.hs b/compiler/GHC/Driver/Errors/Ppr.hs
index b8553c0533..2d90e935c8 100644
--- a/compiler/GHC/Driver/Errors/Ppr.hs
+++ b/compiler/GHC/Driver/Errors/Ppr.hs
@@ -16,7 +16,11 @@ import GHC.Types.Error
import GHC.Unit.Types
import GHC.Utils.Outputable
import GHC.Unit.Module
+import GHC.Unit.State
import GHC.Types.Hint
+import GHC.Types.SrcLoc
+
+import Language.Haskell.Syntax.Decls (RuleDecl(..))
--
-- Suggestions
@@ -121,6 +125,52 @@ instance Diagnostic DriverMessage where
-> mkSimpleDecorated (text "StaticPointers is not supported in GHCi interactive expressions.")
DriverBackpackModuleNotFound modname
-> mkSimpleDecorated (text "module" <+> ppr modname <+> text "was not found")
+ DriverUserDefinedRuleIgnored (HsRule { rd_name = n })
+ -> mkSimpleDecorated $
+ text "Rule \"" <> ftext (snd $ unLoc n) <> text "\" ignored" $+$
+ text "User defined rules are disabled under Safe Haskell"
+ DriverMixedSafetyImport modName
+ -> mkSimpleDecorated $
+ text "Module" <+> ppr modName <+> text ("is imported both as a safe and unsafe import!")
+ DriverCannotLoadInterfaceFile m
+ -> mkSimpleDecorated $
+ text "Can't load the interface file for" <+> ppr m
+ <> text ", to check that it can be safely imported"
+ DriverInferredSafeModule m
+ -> mkSimpleDecorated $
+ quotes (ppr $ moduleName m) <+> text "has been inferred as safe!"
+ DriverInferredSafeImport m
+ -> mkSimpleDecorated $
+ sep
+ [ text "Importing Safe-Inferred module "
+ <> ppr (moduleName m)
+ <> text " from explicitly Safe module"
+ ]
+ DriverMarkedTrustworthyButInferredSafe m
+ -> mkSimpleDecorated $
+ quotes (ppr $ moduleName m) <+> text "is marked as Trustworthy but has been inferred as safe!"
+ DriverCannotImportUnsafeModule m
+ -> mkSimpleDecorated $
+ sep [ ppr (moduleName m)
+ <> text ": Can't be safely imported!"
+ , text "The module itself isn't safe." ]
+ DriverMissingSafeHaskellMode modName
+ -> mkSimpleDecorated $
+ ppr modName <+> text "is missing Safe Haskell mode"
+ DriverPackageNotTrusted state pkg
+ -> mkSimpleDecorated $
+ pprWithUnitState state
+ $ text "The package ("
+ <> ppr pkg
+ <> text ") is required to be trusted but it isn't!"
+ DriverCannotImportFromUntrustedPackage state m
+ -> mkSimpleDecorated $
+ sep [ ppr (moduleName m)
+ <> text ": Can't be safely imported!"
+ , text "The package ("
+ <> (pprWithUnitState state $ ppr (moduleUnit m))
+ <> text ") the module resides in isn't trusted."
+ ]
diagnosticReason = \case
DriverUnknownMessage m
@@ -147,6 +197,26 @@ instance Diagnostic DriverMessage where
-> WarningWithoutFlag
DriverBackpackModuleNotFound{}
-> ErrorWithoutFlag
+ DriverUserDefinedRuleIgnored{}
+ -> WarningWithoutFlag
+ DriverMixedSafetyImport{}
+ -> ErrorWithoutFlag
+ DriverCannotLoadInterfaceFile{}
+ -> ErrorWithoutFlag
+ DriverInferredSafeModule{}
+ -> WarningWithFlag Opt_WarnSafe
+ DriverMarkedTrustworthyButInferredSafe{}
+ ->WarningWithFlag Opt_WarnTrustworthySafe
+ DriverInferredSafeImport{}
+ -> WarningWithFlag Opt_WarnInferredSafeImports
+ DriverCannotImportUnsafeModule{}
+ -> ErrorWithoutFlag
+ DriverMissingSafeHaskellMode{}
+ -> WarningWithFlag Opt_WarnMissingSafeHaskellMode
+ DriverPackageNotTrusted{}
+ -> ErrorWithoutFlag
+ DriverCannotImportFromUntrustedPackage{}
+ -> ErrorWithoutFlag
diagnosticHints = \case
DriverUnknownMessage m
@@ -175,3 +245,23 @@ instance Diagnostic DriverMessage where
-> noHints
DriverBackpackModuleNotFound{}
-> noHints
+ DriverUserDefinedRuleIgnored{}
+ -> noHints
+ DriverMixedSafetyImport{}
+ -> noHints
+ DriverCannotLoadInterfaceFile{}
+ -> noHints
+ DriverInferredSafeModule{}
+ -> noHints
+ DriverInferredSafeImport{}
+ -> noHints
+ DriverCannotImportUnsafeModule{}
+ -> noHints
+ DriverMissingSafeHaskellMode{}
+ -> noHints
+ DriverPackageNotTrusted{}
+ -> noHints
+ DriverMarkedTrustworthyButInferredSafe{}
+ -> noHints
+ DriverCannotImportFromUntrustedPackage{}
+ -> noHints
diff --git a/compiler/GHC/Driver/Errors/Types.hs b/compiler/GHC/Driver/Errors/Types.hs
index 4c593fb681..178455187f 100644
--- a/compiler/GHC/Driver/Errors/Types.hs
+++ b/compiler/GHC/Driver/Errors/Types.hs
@@ -23,10 +23,14 @@ import Data.Typeable
import GHC.Driver.Session
import GHC.Types.Error
import GHC.Unit.Module
+import GHC.Unit.State
import GHC.Parser.Errors.Types ( PsMessage(PsHeaderMessage) )
import GHC.Tc.Errors.Types ( TcRnMessage )
import GHC.HsToCore.Errors.Types ( DsMessage )
+import GHC.Hs.Extension (GhcTc)
+
+import Language.Haskell.Syntax.Decls (RuleDecl)
-- | A collection of warning messages.
-- /INVARIANT/: Each 'GhcMessage' in the collection should have 'SevWarning' severity.
@@ -199,6 +203,140 @@ data DriverMessage where
-}
DriverBackpackModuleNotFound :: !ModuleName -> DriverMessage
+ {-| DriverUserDefinedRuleIgnored is a warning that occurs when user-defined rules
+ are ignored. This typically happens when Safe Haskell.
+
+ Test cases:
+
+ tests/safeHaskell/safeInfered/UnsafeWarn05
+ tests/safeHaskell/safeInfered/UnsafeWarn06
+ tests/safeHaskell/safeInfered/UnsafeWarn07
+ tests/safeHaskell/safeInfered/UnsafeInfered11
+ tests/safeHaskell/safeLanguage/SafeLang03
+ -}
+ DriverUserDefinedRuleIgnored :: !(RuleDecl GhcTc) -> DriverMessage
+
+ {-| DriverMixedSafetyImport is an error that occurs when a module is imported
+ both as safe and unsafe.
+
+ Test cases:
+
+ tests/safeHaskell/safeInfered/Mixed03
+ tests/safeHaskell/safeInfered/Mixed02
+
+ -}
+ DriverMixedSafetyImport :: !ModuleName -> DriverMessage
+
+ {-| DriverCannotLoadInterfaceFile is an error that occurs when we cannot load the interface
+ file for a particular module. This can happen for example in the context of Safe Haskell,
+ when we have to load a module to check if it can be safely imported.
+
+ Test cases: None.
+
+ -}
+ DriverCannotLoadInterfaceFile :: !Module -> DriverMessage
+
+ {-| DriverInferredSafeImport is a warning (controlled by the Opt_WarnSafe flag)
+ that occurs when a module is inferred safe.
+
+ Test cases: None.
+
+ -}
+ DriverInferredSafeModule :: !Module -> DriverMessage
+
+ {-| DriverMarkedTrustworthyButInferredSafe is a warning (controlled by the Opt_WarnTrustworthySafe flag)
+ that occurs when a module is marked trustworthy in SafeHaskell but it has been inferred safe.
+
+ Test cases:
+ tests/safeHaskell/safeInfered/TrustworthySafe02
+ tests/safeHaskell/safeInfered/TrustworthySafe03
+
+ -}
+ DriverMarkedTrustworthyButInferredSafe :: !Module -> DriverMessage
+
+ {-| DriverInferredSafeImport is a warning (controlled by the Opt_WarnInferredSafeImports flag)
+ that occurs when a safe-inferred module is imported from a safe module.
+
+ Test cases: None.
+
+ -}
+ DriverInferredSafeImport :: !Module -> DriverMessage
+
+ {-| DriverCannotImportUnsafeModule is an error that occurs when an usafe module
+ is being imported from a safe one.
+
+ Test cases: None.
+
+ -}
+ DriverCannotImportUnsafeModule :: !Module -> DriverMessage
+
+ {-| DriverMissingSafeHaskellMode is a warning (controlled by the Opt_WarnMissingSafeHaskellMode flag)
+ that occurs when a module is using SafeHaskell features but SafeHaskell mode is not enabled.
+
+ Test cases: None.
+
+ -}
+ DriverMissingSafeHaskellMode :: !Module -> DriverMessage
+
+ {-| DriverPackageNotTrusted is an error that occurs when a package is required to be trusted
+ but it isn't.
+
+ Test cases:
+ tests/safeHaskell/check/Check01
+ tests/safeHaskell/check/Check08
+ tests/safeHaskell/check/Check06
+ tests/safeHaskell/check/pkg01/ImpSafeOnly09
+ tests/safeHaskell/check/pkg01/ImpSafe03
+ tests/safeHaskell/check/pkg01/ImpSafeOnly07
+ tests/safeHaskell/check/pkg01/ImpSafeOnly08
+
+ -}
+ DriverPackageNotTrusted :: !UnitState -> !UnitId -> DriverMessage
+
+ {-| DriverCannotImportFromUntrustedPackage is an error that occurs in the context of
+ Safe Haskell when trying to import a module coming from an untrusted package.
+
+ Test cases:
+ tests/safeHaskell/check/Check09
+ tests/safeHaskell/check/pkg01/ImpSafe01
+ tests/safeHaskell/check/pkg01/ImpSafe04
+ tests/safeHaskell/check/pkg01/ImpSafeOnly03
+ tests/safeHaskell/check/pkg01/ImpSafeOnly05
+ tests/safeHaskell/flags/SafeFlags17
+ tests/safeHaskell/flags/SafeFlags22
+ tests/safeHaskell/flags/SafeFlags23
+ tests/safeHaskell/ghci/p11
+ tests/safeHaskell/ghci/p12
+ tests/safeHaskell/ghci/p17
+ tests/safeHaskell/ghci/p3
+ tests/safeHaskell/safeInfered/UnsafeInfered01
+ tests/safeHaskell/safeInfered/UnsafeInfered02
+ tests/safeHaskell/safeInfered/UnsafeInfered02
+ tests/safeHaskell/safeInfered/UnsafeInfered03
+ tests/safeHaskell/safeInfered/UnsafeInfered05
+ tests/safeHaskell/safeInfered/UnsafeInfered06
+ tests/safeHaskell/safeInfered/UnsafeInfered09
+ tests/safeHaskell/safeInfered/UnsafeInfered10
+ tests/safeHaskell/safeInfered/UnsafeInfered11
+ tests/safeHaskell/safeInfered/UnsafeWarn01
+ tests/safeHaskell/safeInfered/UnsafeWarn03
+ tests/safeHaskell/safeInfered/UnsafeWarn04
+ tests/safeHaskell/safeInfered/UnsafeWarn05
+ tests/safeHaskell/unsafeLibs/BadImport01
+ tests/safeHaskell/unsafeLibs/BadImport06
+ tests/safeHaskell/unsafeLibs/BadImport07
+ tests/safeHaskell/unsafeLibs/BadImport08
+ tests/safeHaskell/unsafeLibs/BadImport09
+ tests/safeHaskell/unsafeLibs/Dep05
+ tests/safeHaskell/unsafeLibs/Dep06
+ tests/safeHaskell/unsafeLibs/Dep07
+ tests/safeHaskell/unsafeLibs/Dep08
+ tests/safeHaskell/unsafeLibs/Dep09
+ tests/safeHaskell/unsafeLibs/Dep10
+
+ -}
+ DriverCannotImportFromUntrustedPackage :: !UnitState -> !Module -> DriverMessage
+
-- | Pass to a 'DriverMessage' the information whether or not the
-- '-fbuilding-cabal-package' flag is set.
data BuildingCabalPackage
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 523d39e3db..6f178afc48 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -565,15 +565,13 @@ tcRnModule' sum save_rn_syntax mod = do
hsc_env <- getHscEnv
dflags <- getDynFlags
- let reason = WarningWithFlag Opt_WarnMissingSafeHaskellMode
let diag_opts = initDiagOpts dflags
-- -Wmissing-safe-haskell-mode
when (not (safeHaskellModeEnabled dflags)
&& wopt Opt_WarnMissingSafeHaskellMode dflags) $
logDiagnostics $ singleMessage $
mkPlainMsgEnvelope diag_opts (getLoc (hpm_module mod)) $
- GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic reason noHints warnMissingSafeHaskellMode
+ GhcDriverMessage $ DriverMissingSafeHaskellMode (ms_mod sum)
tcg_res <- {-# SCC "Typecheck-Rename" #-}
ioMsgMaybe $ hoistTcRnMessage $
@@ -602,25 +600,14 @@ tcRnModule' sum save_rn_syntax mod = do
| safeHaskell dflags == Sf_Safe -> return ()
| otherwise -> (logDiagnostics $ singleMessage $
mkPlainMsgEnvelope diag_opts (warnSafeOnLoc dflags) $
- GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic (WarningWithFlag Opt_WarnSafe) noHints $
- errSafe tcg_res')
+ GhcDriverMessage $ DriverInferredSafeModule (tcg_mod tcg_res'))
False | safeHaskell dflags == Sf_Trustworthy &&
wopt Opt_WarnTrustworthySafe dflags ->
(logDiagnostics $ singleMessage $
mkPlainMsgEnvelope diag_opts (trustworthyOnLoc dflags) $
- GhcDriverMessage $ DriverUnknownMessage $
- mkPlainDiagnostic (WarningWithFlag Opt_WarnTrustworthySafe) noHints $
- errTwthySafe tcg_res')
+ GhcDriverMessage $ DriverMarkedTrustworthyButInferredSafe (tcg_mod tcg_res'))
False -> return ()
return tcg_res'
- where
- pprMod t = ppr $ moduleName $ tcg_mod t
- errSafe t = quotes (pprMod t) <+> text "has been inferred as safe!"
- errTwthySafe t = quotes (pprMod t)
- <+> text "is marked as Trustworthy but has been inferred as safe!"
- warnMissingSafeHaskellMode = ppr (moduleName (ms_mod sum))
- <+> text "is missing Safe Haskell mode"
-- | Convert a typechecked module to Core
hscDesugar :: HscEnv -> ModSummary -> TcGblEnv -> IO ModGuts
@@ -1175,12 +1162,8 @@ hscCheckSafeImports tcg_env = do
warns diag_opts rules = mkMessages $ listToBag $ map (warnRules diag_opts) rules
warnRules :: DiagOpts -> LRuleDecl GhcTc -> MsgEnvelope DriverMessage
- warnRules diag_opts (L loc (HsRule { rd_name = n })) =
- mkPlainMsgEnvelope diag_opts (locA loc) $
- DriverUnknownMessage $
- mkPlainDiagnostic WarningWithoutFlag noHints $
- text "Rule \"" <> ftext (snd $ unLoc n) <> text "\" ignored" $+$
- text "User defined rules are disabled under Safe Haskell"
+ warnRules diag_opts (L loc rule) =
+ mkPlainMsgEnvelope diag_opts (locA loc) $ DriverUserDefinedRuleIgnored rule
-- | Validate that safe imported modules are actually safe. For modules in the
-- HomePackage (the package the module we are compiling in resides) this just
@@ -1256,9 +1239,7 @@ checkSafeImports tcg_env
| imv_is_safe v1 /= imv_is_safe v2
= throwOneError $
mkPlainErrorMsgEnvelope (imv_span v1) $
- GhcDriverMessage $ DriverUnknownMessage $ mkPlainError noHints $
- text "Module" <+> ppr (imv_name v1) <+>
- (text $ "is imported both as a safe and unsafe import!")
+ GhcDriverMessage $ DriverMixedSafetyImport (imv_name v1)
| otherwise
= return v1
@@ -1327,9 +1308,7 @@ hscCheckSafe' m l = do
-- can't load iface to check trust!
Nothing -> throwOneError $
mkPlainErrorMsgEnvelope l $
- GhcDriverMessage $ DriverUnknownMessage $ mkPlainError noHints $
- text "Can't load the interface file for" <+> ppr m
- <> text ", to check that it can be safely imported"
+ GhcDriverMessage $ DriverCannotLoadInterfaceFile m
-- got iface, check trust
Just iface' ->
@@ -1361,30 +1340,13 @@ hscCheckSafe' m l = do
state = hsc_units hsc_env
inferredImportWarn diag_opts = singleMessage
$ mkMsgEnvelope diag_opts l (pkgQual state)
- $ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainDiagnostic (WarningWithFlag Opt_WarnInferredSafeImports) noHints
- $ sep
- [ text "Importing Safe-Inferred module "
- <> ppr (moduleName m)
- <> text " from explicitly Safe module"
- ]
+ $ GhcDriverMessage $ DriverInferredSafeImport m
pkgTrustErr = singleMessage
$ mkErrorMsgEnvelope l (pkgQual state)
- $ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainError noHints
- $ sep [ ppr (moduleName m)
- <> text ": Can't be safely imported!"
- , text "The package ("
- <> (pprWithUnitState state $ ppr (moduleUnit m))
- <> text ") the module resides in isn't trusted."
- ]
+ $ GhcDriverMessage $ DriverCannotImportFromUntrustedPackage state m
modTrustErr = singleMessage
$ mkErrorMsgEnvelope l (pkgQual state)
- $ GhcDriverMessage $ DriverUnknownMessage
- $ mkPlainError noHints
- $ sep [ ppr (moduleName m)
- <> text ": Can't be safely imported!"
- , text "The module itself isn't safe." ]
+ $ GhcDriverMessage $ DriverCannotImportUnsafeModule m
-- | Check the package a module resides in is trusted. Safe compiled
-- modules are trusted without requiring that their package is trusted. For
@@ -1430,12 +1392,7 @@ checkPkgTrust pkgs = do
= (`consBag` acc)
$ mkErrorMsgEnvelope noSrcSpan (pkgQual state)
$ GhcDriverMessage
- $ DriverUnknownMessage
- $ mkPlainError noHints
- $ pprWithUnitState state
- $ text "The package ("
- <> ppr pkg
- <> text ") is required to be trusted but it isn't!"
+ $ DriverPackageNotTrusted state pkg
if isEmptyBag errors
then return ()
else liftIO $ throwErrors $ mkMessages errors
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
-----------------------------------------------------------------------------