Opened 10 years ago

Closed 10 years ago

#4126 closed bug (fixed)

Order of members reversed when a template haskell instance declaration quotation is pretty-printed

Reported by: lilac Owned by:
Priority: normal Milestone: 7.4.1
Component: Template Haskell Version: 6.12.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

This broken file:

{-# LANGUAGE TemplateHaskell #-}                                                                                                                                                                                                             
(+1) [d| instance Monad ((,) a) where return = (,) undefined; (a,x) >>= f = f x |]

Gives the following error:

    No instance for (Num                                                                                                                                                                                                                     
                       (Language.Haskell.TH.Syntax.Q [Language.Haskell.TH.Syntax.Dec]))                                                                                                                                                      
      arising from the literal `1' at test.hs:2:2                                                                                                                                                                                            
    Possible fix:                                                                                                                                                                                                                            
      add an instance declaration for                                                                                                                                                                                                        
      (Num                                                                                                                                                                                                                                   
         (Language.Haskell.TH.Syntax.Q [Language.Haskell.TH.Syntax.Dec]))                                                                                                                                                                    
    In the second argument of `(+)', namely `1'                                                                                                                                                                                              
    In the expression:                                                                                                                                                                                                                       
        (+ 1)                                                                                                                                                                                                                                
          [d|                                                                                                                                                                                                                                
              instance Monad ((,) a) where                                                                                                                                                                                                   
                  { (a, x) >>= f = f x                                                                                                                                                                                                       
                    return = (,) undefined } |]

The error has reversed the order of members in the declaration. However, if I inspect the AST generated from the quotation, they are in the correct order. Hence I suspect the pretty-printer is reversing them.

Change History (2)

comment:1 Changed 10 years ago by igloo

Milestone: 6.16.1

comment:2 Changed 10 years ago by simonpj

Resolution: fixed
Status: newclosed

Excellent point. Thanks for reporting this. Fixed by

Mon Jun 14 17:39:35 BST 2010  simonpj@microsoft.com
  * Don't reverse bindings in rnMethodBinds (fix Trac #4126)

    M ./compiler/rename/RnBinds.lhs -4 +5

It's fairly cosmetic, so I'm not bothering with a regression test.

Simon

Note: See TracTickets for help on using tickets.