diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-01-25 17:14:49 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-01-25 17:14:50 +0100 |
commit | f0f63b39783055b2c0c1a8db8c22749afa6d7329 (patch) | |
tree | 7e857b70f06115f8b19ff009eab09ed19e8aab0f | |
parent | 128b678061120270d3d4fe3eccd1b7dc76a8de35 (diff) | |
download | haskell-f0f63b39783055b2c0c1a8db8c22749afa6d7329.tar.gz |
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
-rw-r--r-- | compiler/main/DynFlags.hs | 22 | ||||
-rw-r--r-- | docs/users_guide/using-warnings.rst | 8 | ||||
-rw-r--r-- | testsuite/tests/driver/T11429a.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/driver/T11429a.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/driver/T11429b.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/driver/T11429c.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/driver/T11429c.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/driver/all.T | 4 | ||||
-rw-r--r-- | utils/mkUserGuidePart/Options/Warnings.hs | 7 |
9 files changed, 50 insertions, 4 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 0a7b6d21a1..f6496d5fa6 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -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 diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst index 4f9a7416d8..10fc9dfb10 100644 --- a/docs/users_guide/using-warnings.rst +++ b/docs/users_guide/using-warnings.rst @@ -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 diff --git a/testsuite/tests/driver/T11429a.hs b/testsuite/tests/driver/T11429a.hs new file mode 100644 index 0000000000..c81fb82437 --- /dev/null +++ b/testsuite/tests/driver/T11429a.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "hello world" diff --git a/testsuite/tests/driver/T11429a.stderr b/testsuite/tests/driver/T11429a.stderr new file mode 100644 index 0000000000..c52b89e33d --- /dev/null +++ b/testsuite/tests/driver/T11429a.stderr @@ -0,0 +1,2 @@ + +on the commandline: warning: unrecognised warning flag: -Wfoobar diff --git a/testsuite/tests/driver/T11429b.hs b/testsuite/tests/driver/T11429b.hs new file mode 100644 index 0000000000..c81fb82437 --- /dev/null +++ b/testsuite/tests/driver/T11429b.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "hello world" diff --git a/testsuite/tests/driver/T11429c.hs b/testsuite/tests/driver/T11429c.hs new file mode 100644 index 0000000000..c81fb82437 --- /dev/null +++ b/testsuite/tests/driver/T11429c.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "hello world" diff --git a/testsuite/tests/driver/T11429c.stderr b/testsuite/tests/driver/T11429c.stderr new file mode 100644 index 0000000000..19e269b2d0 --- /dev/null +++ b/testsuite/tests/driver/T11429c.stderr @@ -0,0 +1,5 @@ + +<no location info>: error: +Failing due to -Werror. + +on the commandline: warning: unrecognised warning flag: -Wfoobar diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T index 69d18d90fa..5a19366e23 100644 --- a/testsuite/tests/driver/all.T +++ b/testsuite/tests/driver/all.T @@ -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']) + diff --git a/utils/mkUserGuidePart/Options/Warnings.hs b/utils/mkUserGuidePart/Options/Warnings.hs index 3c69de7bd5..256d01f9fa 100644 --- a/utils/mkUserGuidePart/Options/Warnings.hs +++ b/utils/mkUserGuidePart/Options/Warnings.hs @@ -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 "++ |