[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 <austin@…>): In [changeset:"09b7943321f89b945d10f8a914f4c2cbf73dff91/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="09b7943321f89b945d10f8a914f4c2cbf73dff91" fix misleading error message regarding function arity Summary: The error reports something like: The function ‘f’ is applied to three arguments, but its type ‘Int -> Float -> Char -> Bool’ has only three The original type was "Monad m => Int -> Float -> m Bool", but "m" was unified with "-> Char". Now it looks better: The function ‘f’ is applied to three arguments, its type is ‘Int -> Float -> m0 Bool’, it is specialized to ‘Int -> Float -> Char -> Bool’ Test Plan: T9605 Reviewers: simonpj, austin Reviewed By: austin Subscribers: carter, thomie Differential Revision: https://phabricator.haskell.org/D556 GHC Trac Issues: #9605 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9605#comment:3> 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 | 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