Skip to content

-ddump-splices parenthesizes QuantifiedConstraints incorrectly in instance declarations

(Originally observed here.)

If you compile this file with GHC 8.6 or later:

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

$([d| class    (c => d) => Implies c d
      instance (c => d) => Implies c d
    |])

You'll get the following -ddump-splices output:

$ /opt/ghc/8.6.5/bin/ghci Bug.hs
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
Bug.hs:(10,3)-(12,6): Splicing declarations
    [d| class (c_a1A7 => d_a1A8) => Implies_a1A6 c_a1A7 d_a1A8
        
        instance (c_a1A9 => d_a1Aa) => Implies_a1A6 c_a1A9 d_a1Aa |]
  ======>
    class c_a4rz => d_a4rA => Implies_a4ry c_a4rz d_a4rA
    instance c_a4rB => d_a4rC => Implies_a4ry c_a4rB d_a4rC

This is wrong, as required parentheses are missing around c => d in both the class and instance declarations.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information