[GHC] #8470: "Fix" spurious Unused do-bind warnings

#8470: "Fix" spurious Unused do-bind warnings ------------------------------------+------------------------------------- Reporter: 2piix | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- I've been writing a lot of monadic code with side effects, and I'm getting a lot of unused do-bind warnings. In particular, consider the contrived example: {{{ performSideEffect :: IO () preformSideEffect = return () someComplicatedIOAction :: a -> IO () someComplicatedIOAction a = do a <- getA performSideEffect putStrLn . show $ a }}} The call to performSideEffect triggers the unused do-bind warning. I can appreciate that we're not binding result of performSideEffect, but we know, by virtue of the type () being a singleton, that there is nothing we can do with the the result. So it "really" doesn't make sense to pull anything out of the action. Fixing the warning with _ <- performSideEffect just adds noise. Would it be possible to turn off the warning in the case that the monad action returns (), or maybe even other singleton types? I'm guessing the latter is harder, and I'd be happy to settle for just (). I don't know enough about GHC's internals to evaluate how hard either would be, though. I know about -fno-warn-unused-do-bind, but it is inconvenient to use in a project that uses -Wall in the Cabal file, which a fairly popular web application framework uses. Even still, catching the legitimate unused do-binds while eliminating these spurious ones would be a nice, noise- lowering addition. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8470: "Fix" spurious Unused do-bind warnings -------------------------------------+------------------------------------ Reporter: 2piix | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by 2piix): Edit: the contrived example contains a "bug" involving name shadowing. "someComplicatedIOAction" doesn't need an argument to get my point across. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8470: "Fix" spurious Unused do-bind warnings -------------------------------------+------------------------------------ Reporter: 2piix | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: worksforme | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by goldfire): * status: new => closed * resolution: => worksforme Comment: I agree that no warning should be emitted for a monadic action that returns `()`. But, I can't seem to reproduce this behavior with 7.6.3. For example, when I compile {{{ {-# OPTIONS_GHC -Wall #-} module Bug where getA :: IO Int getA = return 5 performSideEffect :: IO () performSideEffect = return () someComplicatedIOAction :: IO () someComplicatedIOAction = do a <- getA performSideEffect putStrLn . show $ a }}} I get no warnings. Is there something I'm missing here? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8470: "Fix" spurious Unused do-bind warnings -------------------------------------+------------------------------------ Reporter: 2piix | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: worksforme | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by 2piix): Yes, now that I've looked closer, I'm noticing that the spurious warnings happen when I'm performing an Acid-State update. The full warning is: {{{ src/Yesod/Foundation.hs:476:16: Warning: A do-notation statement discarded a result of type EventResult AddUser. Suppress this warning by saying "_ <- lift (($) acidUpdate Brilliance.Query.AddUser (Brilliance.User.User ((^.) auth Brilliance.userId) f l))" }}} EventResult AddUser ''happens'' to be (), under a type family definition. That is, I have code of the form {{{ instance SomeClass AddUser type EventResult AddUser = () }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8470: "Fix" spurious Unused do-bind warnings -------------------------------------+------------------------------------ Reporter: 2piix | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by monoidal): * status: closed => new * resolution: worksforme => Comment: Here's a testcase showing the incorrect warning {{{ {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fwarn-unused-do-bind #-} data User type family MethodResult ev type instance MethodResult User = () type EventResult a = MethodResult a main = do undefined :: IO (EventResult User) return () }}} @2piix: Please include more information or a complete testcase when reporting, it was hard to reconstruct without knowing what `acidState`, `Brilliance.Query.AddUser` etc. are. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8470: "Fix" spurious Unused do-bind warnings
-------------------------------------+------------------------------------
Reporter: 2piix | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8470: "Fix" spurious Unused do-bind warnings
-------------------------------------+------------------------------------
Reporter: 2piix | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8470: "Fix" spurious Unused do-bind warnings -------------------------------------------------+------------------------- Reporter: 2piix | Owner: Type: feature request | Status: Priority: normal | closed Component: Compiler | Milestone: Resolution: fixed | Version: 7.6.3 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: deSugar/should_compile/T8470 | Unknown/Multiple Blocking: | Difficulty: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by simonpj): * status: new => closed * testcase: => deSugar/should_compile/T8470 * resolution: => fixed Comment: I was in the region, so I arranged to normalise the type before making the check. Works now. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8470#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC