Skip to content

Overlap pragmas generated by TH code are pretty printed with missing "{-#"

Summary

When I generate an instance declaration with Overlap in template haskell:

    InstanceD (Maybe Overlap) Cxt Type [Dec]
           --   ^ Specify "Just someoverlap"

the pretty printed haskell code (as shown by -ddump-splices) is missing "{-#"

Steps to reproduce

$ cat reproducer.hs 
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module TH_pragma_overlap where

class A a

$( [d| instance {-# OVERLAPS #-} A Int |] )
$( [d| instance {-# OVERLAPPABLE #-} A Bool |] )
$( [d| instance {-# OVERLAPPING #-} A () |] )
$( [d| instance {-# INCOHERENT #-} A Char |] )

$ ghc reproducer.hs 
[1 of 1] Compiling TH_pragma_overlap ( reproducer.hs, reproducer.o )
reproducer.hs:7:2-43: Splicing declarations
    [d| instance {-# OVERLAPS #-} A Int |]
  ======>
    instance OVERLAPS #-} A Int
reproducer.hs:8:2-48: Splicing declarations
    [d| instance {-# OVERLAPPABLE #-} A Bool |]
  ======>
    instance OVERLAPPABLE #-} A Bool
reproducer.hs:9:2-45: Splicing declarations
    [d| instance {-# OVERLAPPING #-} A () |]
  ======>
    instance OVERLAPPING #-} A ()
reproducer.hs:10:2-46: Splicing declarations
    [d| instance {-# INCOHERENT #-} A Char |]
  ======>
    instance INCOHERENT #-} A Char

Expected behavior

Pretty printed haskell code in the splices should have pragmas prefixed with "{-# "

Environment

  • GHC version used: 9.6.3
Edited by Jan Hrček
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information