Skip to content

TH-spliced class instances are pretty-printed incorrectly post-#3384

The HsSyn prettyprinter tests patch 499e4382 broke the pretty-printing of Template Haskell-spliced class instances. You can see this for yourself by compiling this code with GHC HEAD:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Bug where

class C a b

$([d| instance C a (Maybe b)
    |])
$ ~/Software/ghc3/inplace/bin/ghc-stage2 --interactive Bug.hs
GHCi, version 8.1.20170126: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
Bug.hs:(9,3)-(10,6): Splicing declarations
    [d| instance C a_a1eC (Maybe b_a1eD) |]
  ======>
    instance C a_a4m5 Maybe b_a4m6

Note the nonsensical instance C a_a4m5 Maybe b_a4m6. For comparison, here is how it should be pretty-printed:

$ /opt/ghc/8.0.2/bin/ghci Bug.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
Bug.hs:(9,3)-(10,6): Splicing declarations
    [d| instance C a_a13N (Maybe b_a13O) |]
  ======>
    instance C a_a3Ju (Maybe b_a3Jv)
Trac metadata
Trac field Value
Version 8.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC alanz
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information