[GHC] #12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Other Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This code compiles without any warnings! {{{#!hs {-# OPTIONS_GHC -Wmissing-methods #-} module Bug where class Foo a where _Bar :: a -> Int instance Foo Int }}} This code, however, //does// emit a warning: {{{#!hs {-# OPTIONS_GHC -Wmissing-methods #-} module Warns where class Foo a where bBar :: a -> Int instance Foo Int }}} {{{ Bug.hs:7:10: warning: [-Wmissing-methods] • No explicit implementation for ‘bBar’ • In the instance declaration for ‘Foo Int’ }}} The only difference is in the name of the class method of `Foo`. Namely, when a class method is prefixed with an underscore, GHC seems to look the other way when checking if any instances are missing an implementation of it. I'd argue that this behavior is incorrect, since I can't envision any scenario in which you'd want the compiler //not// to warn you about missing method implementations (as opposed to, say, not warning about an unused record selector). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by RyanGlScott: @@ -26,1 +26,1 @@ - Bug.hs:7:10: warning: [-Wmissing-methods] + Warn.hs:7:10: warning: [-Wmissing-methods] New description: This code compiles without any warnings! {{{#!hs {-# OPTIONS_GHC -Wmissing-methods #-} module Bug where class Foo a where _Bar :: a -> Int instance Foo Int }}} This code, however, //does// emit a warning: {{{#!hs {-# OPTIONS_GHC -Wmissing-methods #-} module Warns where class Foo a where bBar :: a -> Int instance Foo Int }}} {{{ Warn.hs:7:10: warning: [-Wmissing-methods] • No explicit implementation for ‘bBar’ • In the instance declaration for ‘Foo Int’ }}} The only difference is in the name of the class method of `Foo`. Namely, when a class method is prefixed with an underscore, GHC seems to look the other way when checking if any instances are missing an implementation of it. I'd argue that this behavior is incorrect, since I can't envision any scenario in which you'd want the compiler //not// to warn you about missing method implementations (as opposed to, say, not warning about an unused record selector). -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I believe I've found [http://git.haskell.org/ghc.git/blob/490b9429a8ed3c55d17bf0964fb14582eb206a3d... the function] that's responsible for this behavior: {{{#!hs tcClassMinimalDef :: Name -> [LSig Name] -> [TcMethInfo] -> TcM ClassMinimalDef tcClassMinimalDef _clas sigs op_info = case findMinimalDef sigs of Nothing -> return defMindef Just mindef -> do -- Warn if the given mindef does not imply the default one -- That is, the given mindef should at least ensure that the -- class ops without default methods are required, since we -- have no way to fill them in otherwise whenIsJust (isUnsatisfied (mindef `impliesAtom`) defMindef) $ (\bf -> addWarnTc NoReason (warningMinimalDefIncomplete bf)) return mindef where -- By default require all methods without a default -- implementation whose names don't start with '_' defMindef :: ClassMinimalDef defMindef = mkAnd [ noLoc (mkVar name) | (name, _, Nothing) <- op_info , not (startsWithUnderscore (getOccName name)) ] }}} Notice that `defMindef` deliberately discards method names that begin with an underscore. So fixing this ticket would be a simple matter of removing that line. That being said, I'm worried that there's a comment in this code explicitly calling out the case in which a method's name begins with `_`. Is there a story behind this comment? (e.g., did someone ask for this to be the case?) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: simonpj (added) Comment: At the very least, I've found the commit ( http://git.haskell.org/ghc.git/commit/96f33e63fe913298becbef33bf95daee98fbe4... ) all the way back from 2001 which introduced this quirk: {{{ From 96f33e63fe913298becbef33bf95daee98fbe44d Mon Sep 17 00:00:00 2001 From: unknown <simonpj@MSRC-4971295.europe.corp.microsoft.com> Date: Tue, 24 Sep 2013 20:01:31 +0100 Subject: [PATCH] Move defaultClassMinimalDef from BuildTyCl to TcClassDcl Simple refactoring. Also in Vectorise.Types/TyConDecl, simply propagate the classMinimalDef from the class we are vectorising. Simpler and more direct. --- compiler/iface/BuildTyCl.lhs | 12 +----------- compiler/typecheck/TcClassDcl.lhs | 18 +++++++++++++----- compiler/vectorise/Vectorise/Type/TyConDecl.hs | 4 ++-- 3 files changed, 16 insertions(+), 18 deletions(-) }}} Simon, do you remember why you made this change? The commit description doesn't really allude to it (other than "Simple refactoring"). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by AlexET): You can actually trace it back further to 9aba9a7f16e3f4acd79c75aacdbaad5af92f8752 where it was introduced. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D2849 Comment: Since I consider the current behavior absolutely batty, I've opened Phab:D2849 to correct it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): It's not clear how this behavior was arrived at but I agree that at first glance it doesn't seem desirable. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I don't think there was a deep reason. Currently `-Wunusused-binds` doesn't warn about variables starting with an underscore, so the leading underscore is a per-variable hint that you intend this to be unused and should not warn. So maybe I just naively extended it to the class-method case, which is admittedly a bit different. I have no objection to killing off this special case. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"503219e3e1667ac39607021b2d9586260fbab32b/ghc" 503219e/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="503219e3e1667ac39607021b2d9586260fbab32b" 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 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.2.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | warnings/minimal/WarnMinimal.hs Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * testcase: => warnings/minimal/WarnMinimal.hs -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | warnings/minimal/WarnMinimal.hs Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849, Wiki Page: | Phab:D4476 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D2849 => Phab:D2849, Phab:D4476 Comment: It looks like we forgot to update the users' guide about this. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12959: GHC doesn't warn about missing implementations for class methods beginning with an underscore -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: | warnings/minimal/WarnMinimal.hs Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2849, Wiki Page: | Phab:D4476 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"47e2a28d8c8c80aa9309ceb195ee8671b5a76d3e/ghc" 47e2a28/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="47e2a28d8c8c80aa9309ceb195ee8671b5a76d3e" Remove outdated documentation bits concerning -Wmissing-methods In commit 503219e3e1667ac39607021b2d9586260fbab32b, we stopped suppressing `-Wmissing-methods` warnings on class methods whose names begin with an underscore. However, it seems the users' guide documentation concerning this was never updated. Let's do so. Test Plan: Read it Reviewers: bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #12959 Differential Revision: https://phabricator.haskell.org/D4476 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12959#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC