Commit f0f63b39 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

Implement -Wunrecognised-warning-flag

This allows the user to avoid warnings for warning flags that GHC
doesn't recognise. See #11429 for details..

Test Plan: Validate with T11429[abc] tests

Reviewers: austin, hvr

Reviewed By: hvr

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1830

GHC Trac Issues: #11429
parent 128b6780
......@@ -597,6 +597,7 @@ data WarningFlag =
| Opt_WarnNonCanonicalMonadFailInstances -- since 8.0
| Opt_WarnNonCanonicalMonoidInstances -- since 8.0
| Opt_WarnMissingPatSynSigs -- since 8.0
| Opt_WarnUnrecognisedWarningFlags -- since 8.0
deriving (Eq, Show, Enum)
data Language = Haskell98 | Haskell2010
......@@ -2744,7 +2745,8 @@ dynamic_flags = [
++ map (mkFlag turnOff "XNo" unSetExtensionFlag) xFlags
++ map (mkFlag turnOn "X" setLanguage ) languageFlags
++ map (mkFlag turnOn "X" setSafeHaskell ) safeHaskellFlags
++ [ defFlag "XGenerics"
++ [ unrecognisedWarning
, defFlag "XGenerics"
(NoArg (deprecate $
"it does nothing; look into -XDefaultSignatures " ++
"and -XDeriveGeneric for generic programming support."))
......@@ -2753,6 +2755,16 @@ dynamic_flags = [
"it does nothing; look into -XDefaultSignatures and " ++
"-XDeriveGeneric for generic programming support.")) ]
-- | This is where we handle unrecognised warning flags. We only issue a warning
-- if -Wunrecognised-warning-flags is set. See Trac #11429 for context.
unrecognisedWarning :: Flag (CmdLineP DynFlags)
unrecognisedWarning = defFlag "W" (Prefix action)
where
action :: String -> EwM (CmdLineP DynFlags) ()
action flag = do
f <- wopt Opt_WarnUnrecognisedWarningFlags <$> liftEwM getCmdLineState
when f $ addWarn $ "unrecognised warning flag: -W"++flag
-- See Note [Supporting CLI completion]
package_flags :: [Flag (CmdLineP DynFlags)]
package_flags = [
......@@ -2965,7 +2977,8 @@ wWarningFlags = [
flagSpec "unused-top-binds" Opt_WarnUnusedTopBinds,
flagSpec "warnings-deprecations" Opt_WarnWarningsDeprecations,
flagSpec "wrong-do-bind" Opt_WarnWrongDoBind,
flagSpec "missing-pat-syn-sigs" Opt_WarnMissingPatSynSigs]
flagSpec "missing-pat-syn-sigs" Opt_WarnMissingPatSynSigs,
flagSpec "unrecognised-warning-flags" Opt_WarnUnrecognisedWarningFlags ]
-- | These @-\<blah\>@ flags can all be reversed with @-no-\<blah\>@
negatableFlags :: [FlagSpec GeneralFlag]
......@@ -3464,7 +3477,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
-- please remember to update the User's Guide. The relevant file is:
--
-- * utils/mkUserGuidePart/
-- * docs/users_guide/using.rst
-- * docs/users_guide/using-warnings.rst
-- | Warnings enabled unless specified otherwise
standardWarnings :: [WarningFlag]
......@@ -3487,7 +3500,8 @@ standardWarnings -- see Note [Documenting warning flags]
Opt_WarnInlineRuleShadowing,
Opt_WarnAlternativeLayoutRuleTransitional,
Opt_WarnUnsupportedLlvmVersion,
Opt_WarnTabs
Opt_WarnTabs,
Opt_WarnUnrecognisedWarningFlags
]
-- | Things you get with -W
......
......@@ -31,6 +31,7 @@ generally likely to indicate bugs in your program. These are:
* :ghc-flag:`-Winline-rule-shadowing`
* :ghc-flag:`-Wunsupported-llvm-version`
* :ghc-flag:`-Wtabs`
* :ghc-flag:`-Wunrecognised-warning-flags`
The following flags are simple ways to select standard "packages" of warnings:
......@@ -106,6 +107,13 @@ command line. For backwards compatibility with GHC versions prior to 8.0,
all these warnings can still be controlled with ``-f(no-)warn-*`` instead
of ``-W(no-)*``.
.. ghc-flag:: -Wunrecognised-warning-flags
Enables warnings when the compiler encounters a ``-W...`` flag that is not
recognised.
This warning is on by default.
.. ghc-flag:: -Wtyped-holes
Determines whether the compiler reports typed holes warnings. Has no
......
main :: IO ()
main = putStrLn "hello world"
on the commandline: warning: unrecognised warning flag: -Wfoobar
main :: IO ()
main = putStrLn "hello world"
main :: IO ()
main = putStrLn "hello world"
<no location info>: error:
Failing due to -Werror.
on the commandline: warning: unrecognised warning flag: -Wfoobar
......@@ -467,3 +467,7 @@ test('T10970a', normal, compile_and_run, [''])
test('T4931', normal, compile_and_run, [''])
test('T11182', normal, compile_and_run, [''])
test('T11381', normal, compile_fail, [''])
test('T11429a', normal, compile, ['-Wunrecognised-warning-flags -Wfoobar'])
test('T11429b', normal, compile, ['-Wno-unrecognised-warning-flags -Wfoobar'])
test('T11429c', normal, compile_fail, ['-Wunrecognised-warning-flags -Werror -Wfoobar'])
......@@ -36,6 +36,13 @@ warningsOptions =
, flagType = DynamicFlag
, flagReverse = "-Werror"
}
, flag { flagName = "-Wunrecognised-warning-flags"
, flagDescription =
"throw a warning when an unreconised ``-W...`` flag is "++
"encountered on the command line."
, flagType = DynamicFlag
, flagReverse = "-Wno-unrecognised-warning-flags"
}
, flag { flagName = "-fdefer-type-errors"
, flagDescription =
"Turn type errors into warnings, :ref:`deferring the error until "++
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment