summaryrefslogtreecommitdiff
path: root/testsuite/tests/wcompat-warnings
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2015-12-06 16:08:21 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2015-12-06 16:39:00 +0100
commit986ceb1679b501414b996c520b08ce929a40f94c (patch)
treeacb181dddedd41e6c8927f814430eab92b88ff78 /testsuite/tests/wcompat-warnings
parentdf6794035f1e4397d89896f329525e5368b7d1cc (diff)
downloadhaskell-986ceb1679b501414b996c520b08ce929a40f94c.tar.gz
Implement new `-fwarn-noncanonical-monoid-instances`
This is similiar to the `-fwarn-noncanonical-monad-instances` warning implemented via #11128, but applies to `Semigroup`/`Monoid` instead and the `(<>)`/`mappend` methods (of which `mappend` is planned to move out of `Monoid` at some point in the future being redundant and thus error-prone). This warning is contained in `-Wcompat` but not in `-Wall`. This addresses #11150 Reviewed By: quchen Differential Revision: https://phabricator.haskell.org/D1553
Diffstat (limited to 'testsuite/tests/wcompat-warnings')
-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.stderr16
-rw-r--r--testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs12
5 files changed, 61 insertions, 3 deletions
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs
index 24cab851c9..64a19e5cf9 100644
--- a/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsNotOn.hs
@@ -6,9 +6,21 @@
module WCompatWarningsNotOn where
+import qualified Data.Semigroup as Semi
+
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
(<>) = undefined -- Semigroup warnings
+
+-- -fwarn-noncanonical-monoid-instances
+newtype S = S Int
+
+instance Semi.Semigroup S where
+ (<>) = mappend
+
+instance Semi.Monoid S where
+ S a `mappend` S b = S (a+b)
+ mempty = S 0
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs
index 4c53a1e4ea..6ed25f1ef7 100644
--- a/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOff.hs
@@ -6,9 +6,21 @@
module WCompatWarningsOff where
+import qualified Data.Semigroup as Semi
+
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
(<>) = undefined -- Semigroup warnings
+
+-- -fwarn-noncanonical-monoid-instances
+newtype S = S Int
+
+instance Semi.Semigroup S where
+ (<>) = mappend
+
+instance Semi.Monoid S where
+ S a `mappend` S b = S (a+b)
+ mempty = S 0
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs
index 3b2586aff8..c155f37f42 100644
--- a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.hs
@@ -6,9 +6,21 @@
module WCompatWarningsOn where
+import qualified Data.Semigroup as Semi
+
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
(<>) = undefined -- Semigroup warnings
+
+-- -fwarn-noncanonical-monoid-instances
+newtype S = S Int
+
+instance Semi.Semigroup S where
+ (<>) = mappend
+
+instance Semi.Monoid S where
+ S a `mappend` S b = S (a+b)
+ mempty = S 0
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
index 7b6b501708..5de8745544 100644
--- a/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
@@ -1,12 +1,12 @@
-WCompatWarningsOn.hs:11:5: warning:
+WCompatWarningsOn.hs:13: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:1-27
+ at WCompatWarningsOn.hs:11:1-27
Possible fix:
add (MonadFail m) to the context of
the type signature for:
@@ -20,6 +20,16 @@ WCompatWarningsOn.hs:11:5: warning:
= do { Just _ <- undefined;
undefined }
-WCompatWarningsOn.hs:14:1: warning:
+WCompatWarningsOn.hs:16:1: warning:
Local definition of ‘<>’ clashes with a future Prelude name.
This will become an error in a future release.
+
+WCompatWarningsOn.hs:22:3: warning:
+ Noncanonical ‘(<>) = mappend’ definition detected
+ in the instance declaration for ‘Semigroup S’.
+ Move definition from ‘mappend’ to ‘(<>)’
+
+WCompatWarningsOn.hs:25:3: warning:
+ Noncanonical ‘mappend’ definition detected
+ in the instance declaration for ‘Monoid S’.
+ Define as ‘mappend = (<>)’
diff --git a/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs b/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs
index 2f4aedff23..44f554ee47 100644
--- a/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs
+++ b/testsuite/tests/wcompat-warnings/WCompatWarningsOnOff.hs
@@ -6,9 +6,21 @@
module WCompatWarningsOnOff where
+import qualified Data.Semigroup as Semi
+
monadFail :: Monad m => m a
monadFail = do
Just _ <- undefined
undefined
(<>) = undefined -- Semigroup warnings
+
+-- -fwarn-noncanonical-monoid-instances
+newtype S = S Int
+
+instance Semi.Semigroup S where
+ (<>) = mappend
+
+instance Semi.Monoid S where
+ S a `mappend` S b = S (a+b)
+ mempty = S 0