Skip to content
Snippets Groups Projects
Commit eaf8a06d authored by Krzysztof Gogolewski's avatar Krzysztof Gogolewski Committed by Krzysztof Gogolewski
Browse files

Turn -Wtype-equality-out-of-scope on by default


Also remove -Wnoncanonical-{monoid,monad}-instances from -Wcompat,
since they are enabled by default. Refresh wcompat-warnings/ test
with new -Wcompat warnings.

Part of #24267

Co-authored-by: sheaf's avatarsheaf <sam.derbyshire@gmail.com>
parent afca46a4
No related branches found
No related tags found
No related merge requests found
Showing
with 134 additions and 87 deletions
......@@ -953,7 +953,8 @@ standardWarnings -- see Note [Documenting warning flags]
Opt_WarnBadlyStagedTypes,
Opt_WarnTypeEqualityRequiresOperators,
Opt_WarnInconsistentFlags,
Opt_WarnDataKindsTC
Opt_WarnDataKindsTC,
Opt_WarnTypeEqualityOutOfScope
]
-- | Things you get with -W
......@@ -1002,10 +1003,7 @@ minusWeverythingOpts = [ toEnum 0 .. ]
-- code future compatible to fix issues before they even generate warnings.
minusWcompatOpts :: [WarningFlag]
minusWcompatOpts
= [ Opt_WarnNonCanonicalMonoidInstances
, Opt_WarnNonCanonicalMonadInstances
, Opt_WarnCompatUnqualifiedImports
, Opt_WarnTypeEqualityOutOfScope
= [ Opt_WarnCompatUnqualifiedImports
, Opt_WarnImplicitRhsQuantification
, Opt_WarnDeprecatedTypeAbstractions
]
......
......@@ -78,8 +78,12 @@ as ``-Wno-...`` for every individual warning in the group.
* :ghc-flag:`-Wforall-identifier`
* :ghc-flag:`-Wgadt-mono-local-binds`
* :ghc-flag:`-Wtype-equality-requires-operators`
* :ghc-flag:`-Wtype-equality-out-of-scope`
* :ghc-flag:`-Wbadly-staged-types`
* :ghc-flag:`-Winconsistent-flags`
* :ghc-flag:`-Wnoncanonical-monoid-instances`
* :ghc-flag:`-Wnoncanonical-monad-instances`
* :ghc-flag:`-Wdata-kinds-tc`
.. ghc-flag:: -W
:shortdesc: enable normal warnings
......@@ -165,10 +169,7 @@ as ``-Wno-...`` for every individual warning in the group.
.. hlist::
:columns: 3
* :ghc-flag:`-Wnoncanonical-monoid-instances`
* :ghc-flag:`-Wnoncanonical-monad-instances`
* :ghc-flag:`-Wcompat-unqualified-imports`
* :ghc-flag:`-Wtype-equality-out-of-scope`
* :ghc-flag:`-Wimplicit-rhs-quantification`
* :ghc-flag:`-Wdeprecated-type-abstractions`
......@@ -590,8 +591,6 @@ of ``-W(no-)*``.
* Warn if ``pure`` is defined backwards (i.e. ``pure = return``).
* Warn if ``(*>)`` is defined backwards (i.e. ``(*>) = (>>)``).
This warning is part of the :ghc-flag:`-Wcompat` option group.
.. ghc-flag:: -Wnoncanonical-monadfail-instances
:shortdesc: *(deprecated)*
warn when ``Monad`` or ``MonadFail`` instances have
......@@ -635,8 +634,6 @@ of ``-W(no-)*``.
* Warn if ``(<>)`` is defined backwards (i.e. ``(<>) = mappend``).
This warning is part of the :ghc-flag:`-Wcompat` option group.
.. ghc-flag:: -Wmissing-monadfail-instances
:shortdesc: *(deprecated)*
Warn when a failable pattern is used in a do-block that does
......@@ -2375,6 +2372,7 @@ of ``-W(no-)*``.
:reverse: -Wno-type-equality-out-of-scope
:since: 9.4.1
:default: on
In accordance with `GHC Proposal #371
<https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0371-non-magical-eq.md>`__,
......@@ -2391,9 +2389,6 @@ of ``-W(no-)*``.
custom Prelude. In this case, consider updating your custom Prelude to
re-export ``~`` from ``Data.Type.Equality``.
Being part of the :ghc-flag:`-Wcompat` option group, this warning is off by
default, but will be switched on in a future GHC release.
.. ghc-flag:: -Wtype-equality-requires-operators
:shortdesc: warn when type equality ``a ~ b`` is used despite being out of scope
:type: dynamic
......
......@@ -17,7 +17,6 @@ other dynamic, non-language, flag settings:
-fbreak-points
warning settings:
-Wcompat-unqualified-imports
-Wtype-equality-out-of-scope
-Wimplicit-rhs-quantification
-Wdeprecated-type-abstractions
~~~~~~~~~~ Testing :set -a
......
......@@ -16,7 +16,6 @@ other dynamic, non-language, flag settings:
-fbreak-points
warning settings:
-Wcompat-unqualified-imports
-Wtype-equality-out-of-scope
-Wimplicit-rhs-quantification
-Wdeprecated-type-abstractions
~~~~~~~~~~ Testing :set -a
......
{-# OPTIONS -Wcompat -Wno-error=type-equality-out-of-scope #-}
{-# OPTIONS -Wno-error=type-equality-out-of-scope #-}
module T18862b where
......
T18862b.hs:7:9: warning: [GHC-12003] [-Wtype-equality-out-of-scope (in -Wcompat)]
T18862b.hs:7:9: warning: [GHC-12003] [-Wtype-equality-out-of-scope (in -Wdefault)]
• The ‘~’ operator is out of scope.
Assuming it to stand for an equality constraint.
• NB: ‘~’ used to be built-in syntax but now is a regular type operator
......
module WarnNoncanonical where
import qualified Data.Semigroup as Semi
-- -fwarn-noncanonical-monoid-instances
newtype S = S Int
instance Semi.Semigroup S where
(<>) = mappend
instance Monoid S where
S a `mappend` S b = S (a+b)
mempty = S 0
newtype M a = M a
instance Functor M where
fmap = undefined
instance Applicative M where
liftA2 = undefined
pure = return
(*>) = (>>)
instance Monad M where
return = undefined
(>>=) = undefined
(>>) = undefined
WarnNoncanonical.hs:9:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault)]
Noncanonical ‘(<>) = mappend’ definition detected
in the instance declaration for ‘Semigroup S’.
Suggested fix:
Move definition from ‘mappend’ to ‘(<>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
WarnNoncanonical.hs:12:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault)]
Noncanonical ‘mappend’ definition detected
in the instance declaration for ‘Monoid S’.
‘mappend’ will eventually be removed in favour of ‘(<>)’
Suggested fix:
Either remove definition for ‘mappend’ (recommended) or define as ‘mappend = (<>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
WarnNoncanonical.hs:22:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
Noncanonical ‘pure = return’ definition detected
in the instance declaration for ‘Applicative M’.
Suggested fix:
Move definition from ‘return’ to ‘pure’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
WarnNoncanonical.hs:23:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
Noncanonical ‘(*>) = (>>)’ definition detected
in the instance declaration for ‘Applicative M’.
Suggested fix:
Move definition from ‘(>>)’ to ‘(*>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
WarnNoncanonical.hs:26:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
Noncanonical ‘return’ definition detected
in the instance declaration for ‘Monad M’.
‘return’ will eventually be removed in favour of ‘pure’
Suggested fix:
Either remove definition for ‘return’ (recommended) or define as ‘return = pure’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
WarnNoncanonical.hs:28:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault)]
Noncanonical ‘(>>)’ definition detected
in the instance declaration for ‘Monad M’.
‘(>>)’ will eventually be removed in favour of ‘(*>)’
Suggested fix:
Either remove definition for ‘(>>)’ (recommended) or define as ‘(>>) = (*>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
......@@ -68,3 +68,4 @@ test('T22702b', normal, compile, [''])
test('T22826', normal, compile, [''])
test('T23573', [extra_files(["T23573.hs", "T23573A.hs", "T23573B.hs"])], multimod_compile, ['T23573', '-v0'])
test('T23465', normal, compile, ['-ddump-parsed'])
test('WarnNoncanonical', normal, compile, [''])
{-# LANGUAGE DataKinds #-}
module WCompatWarningsOnOff where
import qualified Data.Semigroup as Semi
import Data.Proxy
import GHC.Types
import Data.List
import Data.Kind
-- -fwarn-noncanonical-monoid-instances
newtype S = S Int
type T1 = 'Nothing :: Maybe a
instance Semi.Semigroup S where
(<>) = mappend
instance Monoid S where
S a `mappend` S b = S (a+b)
mempty = S 0
newtype M a = M a
instance Functor M where
fmap = undefined
instance Applicative M where
liftA2 = undefined
pure = return
(*>) = (>>)
instance Monad M where
return = undefined
(>>=) = undefined
(>>) = undefined
foo :: Maybe a -> Maybe a
foo (Just @b x) = Just @b x
foo _ = Nothing
module Main where
-- base
import Data.List
( intersect )
import System.Exit
( exitFailure, exitSuccess )
-- ghc
import GHC.Driver.Flags
( standardWarnings, minusWcompatOpts )
--------------------------------------------------------------------------------
-- Test that there are no warning flags in both the -Wcompat and -Wdefault
-- warning groups.
main :: IO ()
main = do
case minusWcompatOpts `intersect` standardWarnings of
[] -> exitSuccess
badWarnings -> do
putStrLn $ unlines $
"The following warning flags are in both -Wcompat and -Wdefault:"
: map ((" - " ++) . show) badWarnings
exitFailure
Template.hs:9:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘(<>) = mappend’ definition detected
in the instance declaration for ‘Semigroup S’.
Suggested fix:
Move definition from ‘mappend’ to ‘(<>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
Template.hs:12:3: warning: [GHC-50928] [-Wnoncanonical-monoid-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘mappend’ definition detected
in the instance declaration for ‘Monoid S’.
‘mappend’ will eventually be removed in favour of ‘(<>)’
Suggested fix:
Either remove definition for ‘mappend’ (recommended) or define as ‘mappend = (<>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/semigroup-monoid
Template.hs:22:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘pure = return’ definition detected
in the instance declaration for ‘Applicative M’.
Suggested fix:
Move definition from ‘return’ to ‘pure’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
Template.hs:23:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘(*>) = (>>)’ definition detected
in the instance declaration for ‘Applicative M’.
Suggested fix:
Move definition from ‘(>>)’ to ‘(*>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
Template.hs:26:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘return’ definition detected
in the instance declaration for ‘Monad M’.
‘return’ will eventually be removed in favour of ‘pure’
Suggested fix:
Either remove definition for ‘return’ (recommended) or define as ‘return = pure’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
Template.hs:28:3: warning: [GHC-22705] [-Wnoncanonical-monad-instances (in -Wdefault, -Wcompat)]
Noncanonical ‘(>>)’ definition detected
in the instance declaration for ‘Monad M’.
‘(>>)’ will eventually be removed in favour of ‘(*>)’
Suggested fix:
Either remove definition for ‘(>>)’ (recommended) or define as ‘(>>) = (*>)’
See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
Template.hs:6:8: warning: [GHC-82347] [-Wcompat-unqualified-imports (in -Wcompat)]
To ensure compatibility with future core libraries changes
imports to Data.List should be
either qualified or have an explicit import list.
Template.hs:9:29: warning: [GHC-16382] [-Wimplicit-rhs-quantification (in -Wcompat)]
The variable ‘a’ occurs free on the RHS of the type declaration
In the future GHC will no longer implicitly quantify over such variables
Suggested fix: Bind ‘a’ on the LHS of the type declaration
Template.hs:12:6: warning: [GHC-69797] [-Wdeprecated-type-abstractions (in -Wcompat)]
Type applications in constructor patterns will require
the TypeAbstractions extension starting from GHC 9.14.
Suggested fix: Perhaps you intended to use TypeAbstractions
......@@ -2,3 +2,4 @@
test('WCompatWarningsOn', extra_files(['Template.hs']), compile, [''])
test('WCompatWarningsOff', extra_files(['Template.hs']), compile, [''])
test('WCompatWarningsOnOff', extra_files(['Template.hs']), compile, [''])
test('WCompatDefault', normal, compile_and_run, ['-package ghc'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment