[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

#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

#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
participants (1)
-
GHC