[GHC] #8809: Prettier error messages?

GHC ghc-devs at haskell.org
Thu Feb 20 06:21:35 UTC 2014


#8809: Prettier error messages?
------------------------------------+-------------------------------------
       Reporter:  joelteon          |             Owner:
           Type:  feature request   |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  Compiler          |           Version:  7.9
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
     Difficulty:  Unknown           |         Test Case:
     Blocked By:                    |          Blocking:
Related Tickets:                    |
------------------------------------+-------------------------------------
 `clang` has very nice-looking error messages.


 {{{
 #!html
 <pre><span style="font-weight: bold">pretty.c:6:7: <span style="color:
 pink">warning:</span> incompatible pointer to integer conversion passing
 'char [14]' to parameter of type 'int' [-Wint-conversion]</span>
   foo("Hello, world!");
       <span style="color: green">^~~~~~~~~~~~~~~</span>
 <span style="font-weight: bold">pretty.c:1:14: note: passing argument to
 parameter 'i' here</span>
 void foo(int i) {
              <span style="color: green">^</span>
 1 warning generated.</pre>
 }}}

 `ghc`'s error messages are not so good.

 {{{
 #!html
 <pre>ugly.hs:7:18:
     Couldn't match expected type ‘()’ with actual type
 ‘[Char]’
     In the first argument of ‘f’, namely ‘"Hello,
 world!"’
     In the second argument of ‘($)’, namely ‘f "Hello,
 world!"’
     In the expression: print $ f "Hello, world!"</pre>
 }}}

 In my opinion, there are three independent improvements that could be made
 to GHC error messages and warnings: color, context and whitespace.
 Currently they're blobs of text.

 Consider all three applied to error messages:

 {{{
 #!html
 <pre><strong>ugly.hs:7:18: <span style="color: red">error:</span> Argument
 to 'f' is type '[Char]' but expected 'Int'</strong>
 main = print $ f "Hello, world!"
                  <span style="color: green">^~~~~~~~~~~~~~~</span>

 <strong>ugly.hs:3:1: note: type of 'f' is given here:</strong>
 f :: () -> IO ()
      <span style="color: green">^~</span></pre>
 }}}
 or

 {{{
 #!html
 <pre><strong>ugly.hs: note: type of 'f' is inferred:</strong>
 f :: forall m. Monad m => () -> m ()
                           <span style="color: green">^~</span></pre>
 }}}

 In my opinion, context and whitespace are more important that color. Even
 without color, compare this error message to the one shown above:

 {{{
 ugly.hs:7:18: error: Argument to 'f' is type '[Char]' but expected 'Int'
 main = print $ f "Hello, world!"
                  ^~~~~~~~~~~~~~~

 ugly.hs:3:1: note: type of 'f' is given here:
 f :: () -> IO ()
      ^~
 }}}

 In my opinion this is much easier to visually process than GHC's current
 messages.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8809>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list