summaryrefslogtreecommitdiff
path: root/testsuite/tests/warnings
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/warnings')
-rw-r--r--testsuite/tests/warnings/should_compile/T11128b.hs64
-rw-r--r--testsuite/tests/warnings/should_compile/T11128b.stderr10
-rw-r--r--testsuite/tests/warnings/should_compile/all.T1
3 files changed, 75 insertions, 0 deletions
diff --git a/testsuite/tests/warnings/should_compile/T11128b.hs b/testsuite/tests/warnings/should_compile/T11128b.hs
new file mode 100644
index 0000000000..2cca9a53e0
--- /dev/null
+++ b/testsuite/tests/warnings/should_compile/T11128b.hs
@@ -0,0 +1,64 @@
+{-# LANGUAGE DeriveFunctor #-}
+{-# OPTIONS_GHC -Wnoncanonical-monadfail-instances #-}
+
+-- | Test noncanonical-monadfail-instances warnings
+module T11128b where
+
+import Control.Applicative as A
+import Control.Monad as M
+import Control.Monad.Fail as MF
+
+----------------------------------------------------------------------------
+-- minimal definition
+
+data T0 a = T0 a deriving Functor
+
+instance A.Applicative T0 where
+ pure = T0
+ (<*>) = M.ap
+
+instance M.Monad T0 where
+ (>>=) = undefined
+
+instance MF.MonadFail T0 where
+ fail = error "fail"
+
+----------------------------------------------------------------------------
+-- trigger all 2 warnings
+
+data T1 a = T1 a deriving Functor
+
+instance A.Applicative T1 where
+ pure = return
+ (<*>) = M.ap
+ (*>) = (M.>>)
+
+instance M.Monad T1 where
+ (>>=) = undefined
+ return = T1
+ (>>) = undefined
+ fail = error "fail"
+
+instance MF.MonadFail T1 where
+ fail = M.fail
+
+----------------------------------------------------------------------------
+-- backward compat canonical defintion
+
+data T2 a = T2 a deriving Functor
+
+instance Applicative T2 where
+ pure = T2
+ (<*>) = ap
+ (*>) = undefined
+
+instance M.Monad T2 where
+ (>>=) = undefined
+ return = pure
+ (>>) = (*>)
+ fail = MF.fail
+
+instance MF.MonadFail T2 where
+ fail = error "fail"
+
+----------------------------------------------------------------------------
diff --git a/testsuite/tests/warnings/should_compile/T11128b.stderr b/testsuite/tests/warnings/should_compile/T11128b.stderr
new file mode 100644
index 0000000000..57aa22beea
--- /dev/null
+++ b/testsuite/tests/warnings/should_compile/T11128b.stderr
@@ -0,0 +1,10 @@
+
+T11128b.hs:40:5: warning:
+ Noncanonical ‘fail’ definition detected
+ in the instance declaration for ‘Monad T1’.
+ Either remove definition for ‘fail’ or define as ‘fail = Control.Monad.Fail.fail’
+
+T11128b.hs:43:5: warning:
+ Noncanonical ‘fail = Control.Monad.fail’ definition detected
+ in the instance declaration for ‘MonadFail T1’.
+ Move definition from ‘Control.Monad.fail’ to ‘fail’
diff --git a/testsuite/tests/warnings/should_compile/all.T b/testsuite/tests/warnings/should_compile/all.T
index a2b1860ba4..2e7132213c 100644
--- a/testsuite/tests/warnings/should_compile/all.T
+++ b/testsuite/tests/warnings/should_compile/all.T
@@ -7,6 +7,7 @@ test('T9230', normal, compile_without_flag('-fno-warn-tabs'), [''])
test('T10908', normal, compile, [''])
test('T11077', normal, compile, ['-fwarn-missing-exported-sigs'])
test('T11128', normal, compile, [''])
+test('T11128b', normal, compile, [''])
test('PluralS', normal, compile, [''])
test('DeprU',