Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5509 closed bug (fixed)

quotes pretty-printer not working as comments specify

Reported by: mgsloan1 Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: prettyprint Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I am currently working on a parser for GHC error messages, and would actually prefer that this remain unfixed, as this would make GHC error messages slightly harder to parse.

From compiler/utils/Outputable.lhs

-- quotes encloses something in single quotes...
-- but it omits them if the thing ends in a single quote
-- so that we don't get `foo''.  Instead we just have foo'.
quotes d = SDoc $ \sty -> 
           let pp_d = runSDoc d sty in
           case show pp_d of
             ('\'' : _) -> pp_d
             _other     -> Pretty.quotes pp_d

This implementation does not match the comment - the code is checking for a leading single-quote, not for a trailing one. Therefore the following code does result in the `foo'' that the comment specifically mentions:

foo' :: (Show a) => a -> IO ()
foo' = print
main = foo' print
    No instance for (Show (a0 -> IO ()))
      arising from a use of `foo''
    Possible fix: add an instance declaration for (Show (a0 -> IO ()))
    In the expression: foo' print
    In an equation for `main': main = foo' print

Change History (7)

comment:1 Changed 5 years ago by simonpj

Malcolm Wallace writes: I was bitten by this bug the other day. The code I was modifying had values called


and a type error message told me there was a fault with


so I ended up looking in entirely the wrong place for five minutes.

comment:2 Changed 5 years ago by simonpj

I'm inclined to fix the existing bug, even though it makes mgsloan1's job harder. (But not much harder!)


comment:3 Changed 5 years ago by simonpj@…

commit ba60fc61ba5bbac8d0bbeb719fe26daa4058e1c5

Author: Simon Peyton Jones <>
Date:   Thu Sep 29 09:45:42 2011 +0100

    Make Outputable.quotes do what the comments say
    Outputable.quotes claimed to drop the quotes if the enclosed thing has
    a trailing single quote; but its implementation checked for
    a *leading* quote.
    Fixes Trac #5509

 compiler/utils/Outputable.lhs |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

comment:4 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed


comment:5 Changed 5 years ago by igloo

Would it make more sense to never quote identifiers?

comment:6 Changed 5 years ago by mgsloan1

-- 'quotes' encloses something in single quotes...

hehe, 'nice'. Thanks for the quick fix!

comment:7 in reply to:  5 Changed 5 years ago by simonmar

Replying to igloo:

Would it make more sense to never quote identifiers?

We should use proper Unicode single quotes, if the locale supports Unicode, or better still use coloured output.

Note: See TracTickets for help on using tickets.