Incorrect parenthesization when pretty-printing (Unit ...)
Consider the following code, which utilizes Template Haskell to splice in boxed 1-tuples (i.e., Solo
, formerly Unit
):
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Bug where
import Data.Functor.Identity
import Data.Proxy
import Language.Haskell.TH
f :: $(arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
`appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0))))
f $(conP 'Identity [tupP [tupP []]]) = $(conE 'Identity `appE` tupE [tupE []])
type G = $(conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0)))
Compiling this with GHC 8.10 or HEAD will yield the following -ddump-splices
output:
$ /opt/ghc/8.10.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o, Bug.dyn_o )
Bug.hs:14:12-67: Splicing type
conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))
======>
Proxy 'Unit ()
Bug.hs:(10,8)-(11,74): Splicing type
arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
`appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
======>
Identity Unit () -> Identity Unit ()
Bug.hs:12:5-35: Splicing pattern
conP 'Identity [tupP [tupP []]] ======> Identity Unit()
Bug.hs:12:42-77: Splicing expression
conE 'Identity `appE` tupE [tupE []] ======> Identity Unit ()
This output has four occurrences of incorrect parenthesization. Proxy 'Unit ()
should really be Proxy ('Unit ())
, and Identity Unit ()
should really be Identity (Unit ())
. The culprit is the various *NeedsParens
functions in the GHC API, which do the wrong thing for boxed 1-tuples.
Patch incoming.