summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2023-01-17 08:00:49 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2023-01-17 08:01:02 -0500
commitad6f85a4f5ef331cce265f5eecc67c20a83f8d41 (patch)
treeda4a3c739c70eff28031f9aa3f44df80bf90ddfd
parent496607fdb77baf12e2fe263104ba5d0d700eee3b (diff)
downloadhaskell-wip/T22784.tar.gz
Add missing parenthesizeHsType in cvtSigTypeKindwip/T22784
We need to ensure that the output of `cvtSigTypeKind` is parenthesized (at precedence `sigPrec`) so that any type signatures with an outermost, explicit kind signature can parse correctly. Fixes #22784.
-rw-r--r--compiler/GHC/ThToHs.hs2
-rw-r--r--testsuite/tests/th/T22784.hs7
-rw-r--r--testsuite/tests/th/T22784.stderr6
-rw-r--r--testsuite/tests/th/all.T3
4 files changed, 16 insertions, 2 deletions
diff --git a/compiler/GHC/ThToHs.hs b/compiler/GHC/ThToHs.hs
index 5223d2f7df..4733768ad6 100644
--- a/compiler/GHC/ThToHs.hs
+++ b/compiler/GHC/ThToHs.hs
@@ -1556,7 +1556,7 @@ cvtSigType = cvtSigTypeKind TypeLevel
cvtSigTypeKind :: TypeOrKind -> TH.Type -> CvtM (LHsSigType GhcPs)
cvtSigTypeKind typeOrKind ty = do
ty' <- cvtTypeKind typeOrKind ty
- pure $ hsTypeToHsSigType ty'
+ pure $ hsTypeToHsSigType $ parenthesizeHsType sigPrec ty'
cvtTypeKind :: TypeOrKind -> TH.Type -> CvtM (LHsType GhcPs)
cvtTypeKind typeOrKind ty
diff --git a/testsuite/tests/th/T22784.hs b/testsuite/tests/th/T22784.hs
new file mode 100644
index 0000000000..c2693c9a44
--- /dev/null
+++ b/testsuite/tests/th/T22784.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T22784 where
+
+import Data.Kind
+
+$([d| f :: (Bool :: Type)
+ f = True |])
diff --git a/testsuite/tests/th/T22784.stderr b/testsuite/tests/th/T22784.stderr
new file mode 100644
index 0000000000..39d766a33b
--- /dev/null
+++ b/testsuite/tests/th/T22784.stderr
@@ -0,0 +1,6 @@
+T22784.hs:(6,2)-(7,18): Splicing declarations
+ [d| f :: (Bool :: Type)
+ f = True |]
+ ======>
+ f :: (Bool :: Type)
+ f = True
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index 369ca67855..971fb39056 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -555,4 +555,5 @@ test('Lift_ByteArray', normal, compile_and_run, [''])
test('T21920', normal, compile_and_run, [''])
test('T21723', normal, compile_and_run, [''])
test('T21942', normal, compile_and_run, [''])
-test('TH_fun_par', normal, compile, ['']) \ No newline at end of file
+test('T22784', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
+test('TH_fun_par', normal, compile, [''])