summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Luposchainsky <dluposchainsky@gmail.com>2015-11-24 12:45:00 +0100
committerBen Gamari <ben@smart-cactus.org>2015-11-24 14:02:58 +0100
commit6d147939628c8503d682ffbe2985ca435d7a7c1d (patch)
treeeb488f759377137f003a99c248a8d6dc2025b1c3
parentc05fdddec71f9dc8ebe62d751ccf03367128072a (diff)
downloadhaskell-6d147939628c8503d682ffbe2985ca435d7a7c1d.tar.gz
Add -Wcompat warning flag group
Reviewers: hvr, austin, thomie, bgamari Reviewed By: hvr, austin, thomie, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1495 GHC Trac Issues: #11000
-rw-r--r--compiler/main/DynFlags.hs31
-rw-r--r--docs/users_guide/7.12.1-notes.rst11
-rw-r--r--docs/users_guide/using-warnings.rst22
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs12
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs12
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs12
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr21
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs12
-rw-r--r--testsuite/tests/wcompat-warnings/all.T4
-rw-r--r--utils/mkUserGuidePart/Options/Warnings.hs7
10 files changed, 133 insertions, 11 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index ad05ed5a4d..f386d8d40c 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -2570,13 +2570,15 @@ dynamic_flags = [
, defGhcFlag "mavx512pf" (noArg (\d -> d{ avx512pf = True }))
------ Warning opts -------------------------------------------------
- , defFlag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
- , defFlag "Werror" (NoArg (setGeneralFlag Opt_WarnIsError))
- , defFlag "Wwarn" (NoArg (unSetGeneralFlag Opt_WarnIsError))
- , defFlag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
- , defFlag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
- deprecate "Use -w instead"))
- , defFlag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
+ , defFlag "W" (NoArg (mapM_ setWarningFlag minusWOpts))
+ , defFlag "Werror" (NoArg (setGeneralFlag Opt_WarnIsError))
+ , defFlag "Wwarn" (NoArg (unSetGeneralFlag Opt_WarnIsError))
+ , defFlag "Wcompat" (NoArg (mapM_ setWarningFlag minusWcompatOpts))
+ , defFlag "Wno-compat" (NoArg (mapM_ unSetWarningFlag minusWcompatOpts))
+ , defFlag "Wall" (NoArg (mapM_ setWarningFlag minusWallOpts))
+ , defFlag "Wnot" (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
+ deprecate "Use -w instead"))
+ , defFlag "w" (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))
------ Plugin flags ------------------------------------------------
, defGhcFlag "fplugin-opt" (hasArg addPluginModuleNameOption)
@@ -3416,6 +3418,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
--
-- * docs/users_guide/using.xml
+-- | Warnings enabled unless specified otherwise
standardWarnings :: [WarningFlag]
standardWarnings -- see Note [Documenting warning flags]
= [ Opt_WarnOverlappingPatterns,
@@ -3441,8 +3444,8 @@ standardWarnings -- see Note [Documenting warning flags]
Opt_WarnTabs
]
+-- | Things you get with -W
minusWOpts :: [WarningFlag]
--- Things you get with -W
minusWOpts
= standardWarnings ++
[ Opt_WarnUnusedTopBinds,
@@ -3455,8 +3458,8 @@ minusWOpts
Opt_WarnDodgyImports
]
+-- | Things you get with -Wall
minusWallOpts :: [WarningFlag]
--- Things you get with -Wall
minusWallOpts
= minusWOpts ++
[ Opt_WarnTypeDefaults,
@@ -3469,6 +3472,16 @@ minusWallOpts
Opt_WarnUntickedPromotedConstructors
]
+-- | Things you get with -Wcompat.
+--
+-- This is intended to group together warnings that will be enabled by default
+-- at some point in the future, so that library authors eager to make their
+-- code future compatible to fix issues before they even generate warnings.
+minusWcompatOpts :: [WarningFlag]
+minusWcompatOpts
+ = [ Opt_WarnMissingMonadFailInstance
+ ]
+
enableUnusedBinds :: DynP ()
enableUnusedBinds = mapM_ setWarningFlag unusedBindsFlags
diff --git a/docs/users_guide/7.12.1-notes.rst b/docs/users_guide/7.12.1-notes.rst
index 511111f1a0..4456454503 100644
--- a/docs/users_guide/7.12.1-notes.rst
+++ b/docs/users_guide/7.12.1-notes.rst
@@ -152,6 +152,17 @@ Compiler
- When printing an out-of-scope error message, GHC will give helpful advice if
the error might be caused by too restrictive imports.
+- Added the ``-Wcompat`` warning group, along with its opposite
+ ``-Wno-compat``. Turns on warnings that will be enabled by default in the
+ future, but remain off in normal compilations for the time being. This
+ allows library authors eager to make their code future compatible to adapt
+ to new features before they even generate warnings.
+
+- Added the ``-fwarn-missing-monadfail-instance`` flag. When enabled, this
+ will issue a warning if a failable pattern is used in a context that does
+ not have a ``MonadFail`` constraint. This flag represents phase 1 of the
+ MonadFail proposal (MFP).
+
GHCi
~~~~
diff --git a/docs/users_guide/using-warnings.rst b/docs/users_guide/using-warnings.rst
index 5118168a8c..5bec157b06 100644
--- a/docs/users_guide/using-warnings.rst
+++ b/docs/users_guide/using-warnings.rst
@@ -45,6 +45,23 @@ standard “packages” of warnings:
``-fwarn-missing-exported-sigs``, ``-fwarn-missing-import-lists``
and ``-fwarn-identities``.
+``-Wcompat``
+ .. index::
+ single: -Wcompat
+
+ Turns on warnings that will be enabled by default in the future, but remain
+ off in normal compilations for the time being. This allows library authors
+ eager to make their code future compatible to adapt to new features before
+ they even generate warnings.
+
+ This currently enables only ``-fwarn-missing-monadfail-instance``.
+
+``-Wno-compat``
+ .. index::
+ single: -Wno-compat
+
+ Disables all warnings enabled by ``-Wcompat``.
+
``-w``
.. index::
single: -w
@@ -223,8 +240,9 @@ command line.
Warn when a failable pattern is used in a do-block that does not have a
``MonadFail`` instance.
- This option is off by default, but will be switched on in a future GHC
- release, as part of the MFP (MonadFail Proposal).
+ Being part of the ``-Wcompat`` option group, this warning is off by
+ default, but will be switched on in a future GHC release, as part of
+ the MFP (MonadFail Proposal).
``-fwarn-deprecated-flags``
.. index::
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs
new file mode 100644
index 0000000000..2f86d46bc2
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs
@@ -0,0 +1,12 @@
+-- Test purpose:
+-- Ensure that not using -Wcompat does not enable its warnings
+
+-- {-# OPTIONS_GHC -Wcompat #-}
+-- {-# OPTIONS_GHC -Wno-compat #-}
+
+module WCompatWarningsNotOn where
+
+monadFail :: Monad m => m a
+monadFail = do
+ Just _ <- undefined
+ undefined
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs
new file mode 100644
index 0000000000..727a4e7600
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs
@@ -0,0 +1,12 @@
+-- Test purpose:
+-- Ensure that using -Wno-compat does not switch on warnings
+
+-- {-# OPTIONS_GHC -Wcompat #-}
+{-# OPTIONS_GHC -Wno-compat #-}
+
+module WCompatWarningsOff where
+
+monadFail :: Monad m => m a
+monadFail = do
+ Just _ <- undefined
+ undefined
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs
new file mode 100644
index 0000000000..29fcc9eeb3
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs
@@ -0,0 +1,12 @@
+-- Test purpose:
+-- Ensure that -Wcompat switches on the right warnings
+
+{-# OPTIONS_GHC -Wcompat #-}
+-- {-# OPTIONS_GHC -Wno-compat #-}
+
+module WCompatWarningsOn where
+
+monadFail :: Monad m => m a
+monadFail = do
+ Just _ <- undefined
+ undefined
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
new file mode 100644
index 0000000000..03fc4e26c1
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
@@ -0,0 +1,21 @@
+
+WCompatWarningsOn.hs:11:5: warning:
+ Could not deduce (MonadFail m)
+ arising from the failable pattern ‘Just _’
+ (this will become an error a future GHC release)
+ from the context: Monad m
+ bound by the type signature for:
+ monadFail :: Monad m => m a
+ at WCompatWarningsOn.hs:9:14-27
+ Possible fix:
+ add (MonadFail m) to the context of
+ the type signature for:
+ monadFail :: Monad m => m a
+ In a stmt of a 'do' block: Just _ <- undefined
+ In the expression:
+ do { Just _ <- undefined;
+ undefined }
+ In an equation for ‘monadFail’:
+ monadFail
+ = do { Just _ <- undefined;
+ undefined }
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs
new file mode 100644
index 0000000000..26d3973702
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs
@@ -0,0 +1,12 @@
+-- Test purpose:
+-- Ensure that -Wno-compat disables a previously set -Wcompat
+
+{-# OPTIONS_GHC -Wcompat #-}
+{-# OPTIONS_GHC -Wno-compat #-}
+
+module WCompatWarningsOnOff where
+
+monadFail :: Monad m => m a
+monadFail = do
+ Just _ <- undefined
+ undefined
diff --git a/testsuite/tests/wcompat-warnings/all.T b/testsuite/tests/wcompat-warnings/all.T
new file mode 100644
index 0000000000..4447f994cb
--- /dev/null
+++ b/testsuite/tests/wcompat-warnings/all.T
@@ -0,0 +1,4 @@
+test('WCompatWarningsOn', normal, compile, [''])
+test('WCompatWarningsOff', normal, compile, [''])
+test('WCompatWarningsNotOn', normal, compile, [''])
+test('WCompatWarningsOnOff', normal, compile, [''])
diff --git a/utils/mkUserGuidePart/Options/Warnings.hs b/utils/mkUserGuidePart/Options/Warnings.hs
index e6c6333108..563ce94ab1 100644
--- a/utils/mkUserGuidePart/Options/Warnings.hs
+++ b/utils/mkUserGuidePart/Options/Warnings.hs
@@ -19,6 +19,13 @@ warningsOptions =
, flagType = DynamicFlag
, flagReverse = "-w"
}
+ , flag { flagName = "-Wcompat"
+ , flagDescription =
+ "enable future compatibility warnings " ++
+ "(details in :ref:`options-sanity`)"
+ , flagType = DynamicFlag
+ , flagReverse = "-Wno-compat"
+ }
, flag { flagName = "-Werror"
, flagDescription = "make warnings fatal"
, flagType = DynamicFlag