[Git][ghc/ghc][master] Turn -Wtype-equality-out-of-scope on by default
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat Jan 13 02:16:19 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
eaf8a06d by Krzysztof Gogolewski at 2024-01-11T00:43:17+01:00
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 <sam.derbyshire at gmail.com>
- - - - -
13 changed files:
- compiler/GHC/Driver/Flags.hs
- docs/users_guide/using-warnings.rst
- testsuite/tests/ghci/scripts/ghci024.stdout
- testsuite/tests/ghci/scripts/ghci024.stdout-mingw32
- testsuite/tests/warnings/should_compile/T18862b.hs
- testsuite/tests/warnings/should_compile/T18862b.stderr
- + testsuite/tests/warnings/should_compile/WarnNoncanonical.hs
- + testsuite/tests/warnings/should_compile/WarnNoncanonical.stderr
- testsuite/tests/warnings/should_compile/all.T
- testsuite/tests/wcompat-warnings/Template.hs
- + testsuite/tests/wcompat-warnings/WCompatDefault.hs
- testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
- testsuite/tests/wcompat-warnings/all.T
Changes:
=====================================
compiler/GHC/Driver/Flags.hs
=====================================
@@ -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
]
=====================================
docs/users_guide/using-warnings.rst
=====================================
@@ -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
=====================================
testsuite/tests/ghci/scripts/ghci024.stdout
=====================================
@@ -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
=====================================
testsuite/tests/ghci/scripts/ghci024.stdout-mingw32
=====================================
@@ -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
=====================================
testsuite/tests/warnings/should_compile/T18862b.hs
=====================================
@@ -1,4 +1,4 @@
-{-# OPTIONS -Wcompat -Wno-error=type-equality-out-of-scope #-}
+{-# OPTIONS -Wno-error=type-equality-out-of-scope #-}
module T18862b where
=====================================
testsuite/tests/warnings/should_compile/T18862b.stderr
=====================================
@@ -1,5 +1,5 @@
-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
=====================================
testsuite/tests/warnings/should_compile/WarnNoncanonical.hs
=====================================
@@ -0,0 +1,28 @@
+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
=====================================
testsuite/tests/warnings/should_compile/WarnNoncanonical.stderr
=====================================
@@ -0,0 +1,45 @@
+
+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
=====================================
testsuite/tests/warnings/should_compile/all.T
=====================================
@@ -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, [''])
=====================================
testsuite/tests/wcompat-warnings/Template.hs
=====================================
@@ -1,28 +1,13 @@
+{-# 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
=====================================
testsuite/tests/wcompat-warnings/WCompatDefault.hs
=====================================
@@ -0,0 +1,26 @@
+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
=====================================
testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
=====================================
@@ -1,45 +1,15 @@
-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
=====================================
testsuite/tests/wcompat-warnings/all.T
=====================================
@@ -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'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eaf8a06de671f4d31124ac3869a473753686a50b
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eaf8a06de671f4d31124ac3869a473753686a50b
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240112/956a8309/attachment-0001.html>
More information about the ghc-commits
mailing list