summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-08-26 09:23:54 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-08-27 14:20:01 -0400
commitbacccb73c9b080c3c01a5e55ecb0a00cd8a77e55 (patch)
treeb3807157c7c0b59abccdf1c732e5c9ce99c6e9c0 /testsuite
parent01ff8c89727a91cbc1571ae54f73f5919d6aaa71 (diff)
downloadhaskell-bacccb73c9b080c3c01a5e55ecb0a00cd8a77e55.tar.gz
Make {hsExpr,hsType,pat}NeedsParens aware of boxed 1-tuples
`hsExprNeedsParens`, `hsTypeNeedsParens`, and `patNeedsParens` previously assumed that all uses of explicit tuples in the source syntax never need to be parenthesized. This is true save for one exception: boxed one-tuples, which use the `Solo` data type from `GHC.Tuple` instead of special tuple syntax. This patch adds the necessary logic to the three `*NeedsParens` functions to handle `Solo` correctly. Fixes #18612.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/th/T18612.hs14
-rw-r--r--testsuite/tests/th/T18612.stderr13
-rw-r--r--testsuite/tests/th/all.T1
3 files changed, 28 insertions, 0 deletions
diff --git a/testsuite/tests/th/T18612.hs b/testsuite/tests/th/T18612.hs
new file mode 100644
index 0000000000..ea7c007c51
--- /dev/null
+++ b/testsuite/tests/th/T18612.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# OPTIONS_GHC -ddump-splices #-}
+module T18612 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)))
diff --git a/testsuite/tests/th/T18612.stderr b/testsuite/tests/th/T18612.stderr
new file mode 100644
index 0000000000..25286ef671
--- /dev/null
+++ b/testsuite/tests/th/T18612.stderr
@@ -0,0 +1,13 @@
+T18612.hs:14:11-68: Splicing type
+ conT ''Proxy `appT` (promotedTupleT 1 `appT` (tupleT 0))
+ ======>
+ Proxy ('Solo ())
+T18612.hs:(10,7)-(11,75): Splicing type
+ arrowT `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
+ `appT` (conT ''Identity `appT` (tupleT 1 `appT` (tupleT 0)))
+ ======>
+ Identity (Solo ()) -> Identity (Solo ())
+T18612.hs:12:4-36: Splicing pattern
+ conP 'Identity [tupP [tupP []]] ======> Identity (Solo())
+T18612.hs:12:41-78: Splicing expression
+ conE 'Identity `appE` tupE [tupE []] ======> Identity (Solo ())
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 6d4a5036d7..e53b0d872a 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -513,3 +513,4 @@ test('T18102b', extra_files(['T18102b_aux.hs']), compile_and_run, [''])
test('T18121', normal, compile, [''])
test('T18123', normal, compile, [''])
test('T18388', normal, compile, [''])
+test('T18612', normal, compile, [''])