Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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
Test.hs:3:8:
    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 3 years ago by simonpj

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

    foo
    foo'
    foo''

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

   `foo''

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

comment:2 Changed 3 years ago by simonpj

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

S

comment:3 Changed 3 years ago by simonpj@…

commit ba60fc61ba5bbac8d0bbeb719fe26daa4058e1c5

Author: Simon Peyton Jones <simonpj@microsoft.com>
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 3 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

Done.

comment:5 follow-up: Changed 3 years ago by igloo

Would it make more sense to never quote identifiers?

comment:6 Changed 3 years ago by mgsloan1

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

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

comment:7 in reply to: ↑ 5 Changed 3 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.