[GHC] #9605: Misleading error message with forgotten "do"

#9605: Misleading error message with forgotten "do" -------------------------------------+------------------------------------- Reporter: owst | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- In the following (simplified) code, I forgot to add the do keyword, when doing some refactoring. This caused GHC to give a strange error message that said approximately "The function F is applied to two arguments, but its type T has only two"... which is odd! {{{#!hs import Control.Monad.RWS ( evalRWS, RWS ) import Control.Monad.Writer.Class ( tell ) main = print $ evalRWS (go 1) () () go :: Int -> RWS () [String] () () go i = --Oops, forgot a do here return (show i) >>= (\l -> tell [l]) -- go $ i + 1 go i }}} Strangely, replacing the "go i" line with the commented-out line above it gives a sensible error message, the "Possible cause: `\l -> tell [l]' is applied to too many arguments" message, which is correct, and would've pointed me straight to the problem. The invalid error message, which appears to be the same using GHC 7.6.3 and 7.8.3, is: {{{ NFA.hs:8:25: Couldn't match type ‘String -> Control.Monad.Trans.RWS.Lazy.RWST () [String] () Data.Functor.Identity.Identity ()’ with ‘()’ Expected type: Int -> String -> Control.Monad.Trans.RWS.Lazy.RWST () [String] () Data.Functor.Identity.Identity () Actual type: Int -> () The function ‘\ l -> tell [l]’ is applied to two arguments, but its type ‘(Int -> RWS () [String] () ()) -> Int -> ()’ has only two In the second argument of ‘(>>=)’, namely ‘(\ l -> tell [l]) go i’ In the expression: return (show i) >>= (\ l -> tell [l]) go i }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9605 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9605: Misleading error message with forgotten "do" -------------------------------------+------------------------------------- Reporter: owst | Owner: Yuras Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #7869 None/Unknown | Test Case: | Blocking: | Differential Revisions: D556 | -------------------------------------+------------------------------------- Changes (by Yuras): * owner: => Yuras * differential: => D556 * component: Compiler => Compiler (Type checker) * related: => #7869 Comment: I prepared a patch to skip "but its type T has only two" part here, and report only inferred type. Any ideas how to improve the error message further? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9605#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9605: Misleading error message with forgotten "do" -------------------------------------+------------------------------------- Reporter: owst | Owner: Yuras Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #7869 None/Unknown | Test Case: | Blocking: | Differential Revisions: Phab:D556 | -------------------------------------+------------------------------------- Changes (by Yuras): * differential: D556 => Phab:D556 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9605#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9605: Misleading error message with forgotten "do"
-------------------------------------+-------------------------------------
Reporter: owst | Owner: Yuras
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
(Type checker) | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: | Related Tickets: #7869
None/Unknown |
Test Case: |
Blocking: |
Differential Revisions: Phab:D556 |
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#9605: Misleading error message with forgotten "do" -------------------------------------+------------------------------------- Reporter: owst | Owner: Yuras Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 (Type checker) | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #7869 None/Unknown | Test Case: | Blocking: | Differential Revisions: Phab:D556 | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: new => closed * resolution: => fixed * milestone: => 7.10.1 Comment: I think the pushed revision is fine, so this is done. Thanks Yuras! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9605#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9605: Misleading error message with forgotten "do" -------------------------------------+------------------------------------- Reporter: owst | Owner: Yuras Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler (Type | Version: 7.8.3 checker) | Keywords: Resolution: fixed | TypeErrorMessages Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7869 | Differential Rev(s): Phab:D556 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => TypeErrorMessages -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9605#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC