[commit: ghc] master: Warn about missing instance methods that start with an underscore (503219e)

git at git.haskell.org git at git.haskell.org
Thu Dec 15 18:07:50 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/503219e3e1667ac39607021b2d9586260fbab32b/ghc

>---------------------------------------------------------------

commit 503219e3e1667ac39607021b2d9586260fbab32b
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Thu Dec 15 11:17:49 2016 -0500

    Warn about missing instance methods that start with an underscore
    
    Previously, GHC would not warn whenever there was a class instance that
    didn't implement a class method whose name begins with an underscore.
    
    Fixes #12959.
    
    Test Plan: make test TEST=WarnMinimal
    
    Reviewers: austin, bgamari, simonpj
    
    Reviewed By: bgamari, simonpj
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2849
    
    GHC Trac Issues: #12959


>---------------------------------------------------------------

503219e3e1667ac39607021b2d9586260fbab32b
 compiler/typecheck/TcClassDcl.hs                    |  6 ++----
 docs/users_guide/8.2.1-notes.rst                    | 12 ++++++++++++
 testsuite/tests/warnings/minimal/WarnMinimal.hs     |  4 ++--
 testsuite/tests/warnings/minimal/WarnMinimal.stderr |  8 +++++++-
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/compiler/typecheck/TcClassDcl.hs b/compiler/typecheck/TcClassDcl.hs
index 162e91a..c5a4c3a 100644
--- a/compiler/typecheck/TcClassDcl.hs
+++ b/compiler/typecheck/TcClassDcl.hs
@@ -293,12 +293,10 @@ tcClassMinimalDef _clas sigs op_info
                    (\bf -> addWarnTc NoReason (warningMinimalDefIncomplete bf))
         return mindef
   where
-    -- By default require all methods without a default
-    -- implementation whose names don't start with '_'
+    -- By default require all methods without a default implementation
     defMindef :: ClassMinimalDef
     defMindef = mkAnd [ noLoc (mkVar name)
-                      | (name, _, Nothing) <- op_info
-                      , not (startsWithUnderscore (getOccName name)) ]
+                      | (name, _, Nothing) <- op_info ]
 
 instantiateMethod :: Class -> Id -> [TcType] -> TcType
 -- Take a class operation, say
diff --git a/docs/users_guide/8.2.1-notes.rst b/docs/users_guide/8.2.1-notes.rst
index 2e9033c..3011a29 100644
--- a/docs/users_guide/8.2.1-notes.rst
+++ b/docs/users_guide/8.2.1-notes.rst
@@ -100,6 +100,18 @@ Compiler
 - The Mingw-w64 toolchain for the Windows version of GHC has been updated. GHC now uses
   `GCC 6.2.0` and `binutils 2.27`.
 
+- Previously, :ghc-flag:`-Wmissing-methods` would not warn whenever a type
+  class method beginning with an underscore was not implemented in an instance.
+  For instance, this code would compile without any warnings: ::
+
+     class Foo a where
+       _Bar :: a -> Int
+
+     instance Foo Int
+
+  :ghc-flag:`-Wmissing-methods` will now warn that ``_Bar`` is not implemented
+  in the ``Foo Int`` instance.
+
 GHCi
 ~~~~
 
diff --git a/testsuite/tests/warnings/minimal/WarnMinimal.hs b/testsuite/tests/warnings/minimal/WarnMinimal.hs
index d369065..d6c9b7b 100644
--- a/testsuite/tests/warnings/minimal/WarnMinimal.hs
+++ b/testsuite/tests/warnings/minimal/WarnMinimal.hs
@@ -87,7 +87,7 @@ class Cheater a where  -- WARNING LINE
 
 class Cheater2 a where
   _cheater2 :: a
-  {-# MINIMAL #-} -- no warning
+  {-# MINIMAL #-} -- warning!
 
 class Cheater3 a where  -- WARNING LINE
   cheater3, cheater3b :: a
@@ -100,7 +100,7 @@ instance Num Bool where  -- WARNING LINE
 
 class NoExplicit a where
   needed :: a
-  _optional :: a
+  _alsoNeeded :: a
 
 instance NoExplicit Int where  -- WARNING LINE
 
diff --git a/testsuite/tests/warnings/minimal/WarnMinimal.stderr b/testsuite/tests/warnings/minimal/WarnMinimal.stderr
index d907a6c..4323a91 100644
--- a/testsuite/tests/warnings/minimal/WarnMinimal.stderr
+++ b/testsuite/tests/warnings/minimal/WarnMinimal.stderr
@@ -30,6 +30,12 @@ WarnMinimal.hs:84:1: warning:
       but there is no default implementation.
     • In the class declaration for ‘Cheater’
 
+WarnMinimal.hs:88:1: warning:
+    • The MINIMAL pragma does not require:
+        ‘_cheater2’
+      but there is no default implementation.
+    • In the class declaration for ‘Cheater2’
+
 WarnMinimal.hs:92:1: warning:
     • The MINIMAL pragma does not require:
         ‘cheater3b’
@@ -45,7 +51,7 @@ WarnMinimal.hs:99:10: warning: [-Wmissing-methods (in -Wdefault)]
 
 WarnMinimal.hs:105:10: warning: [-Wmissing-methods (in -Wdefault)]
     • No explicit implementation for
-        ‘needed’
+        ‘needed’ and ‘_alsoNeeded’
     • In the instance declaration for ‘NoExplicit Int’
 
 WarnMinimal.hs:116:10: warning: [-Wmissing-methods (in -Wdefault)]



More information about the ghc-commits mailing list