Parenthesize nullary constraint tuples using sigPrec (#17403)
authorRyan Scott <ryan.gl.scott@gmail.com>
Fri, 25 Oct 2019 22:30:55 +0000 (18:30 -0400)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sun, 27 Oct 2019 15:36:17 +0000 (11:36 -0400)
We were using `appPrec`, not `sigPrec`, as the precedence when
determining whether or not to parenthesize `() :: Constraint`,
which lead to the parentheses being omitted in function contexts
like `(() :: Constraint) => String`. Easily fixed.

Fixes #17403.

compiler/iface/IfaceType.hs
testsuite/tests/ghci/scripts/T17403.hs [new file with mode: 0644]
testsuite/tests/ghci/scripts/T17403.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T17403.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index acf1161..2ca9319 100644 (file)
@@ -1467,7 +1467,7 @@ pprSum _arity is_promoted args
 
 pprTuple :: PprPrec -> TupleSort -> PromotionFlag -> IfaceAppArgs -> SDoc
 pprTuple ctxt_prec ConstraintTuple NotPromoted IA_Nil
-  = maybeParen ctxt_prec appPrec $
+  = maybeParen ctxt_prec sigPrec $
     text "() :: Constraint"
 
 -- All promoted constructors have kind arguments
diff --git a/testsuite/tests/ghci/scripts/T17403.hs b/testsuite/tests/ghci/scripts/T17403.hs
new file mode 100644 (file)
index 0000000..5112ffa
--- /dev/null
@@ -0,0 +1,8 @@
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE KindSignatures #-}
+module T17403 where
+
+import Data.Kind
+
+f :: (() :: Constraint) => String
+f = "hello world"
diff --git a/testsuite/tests/ghci/scripts/T17403.script b/testsuite/tests/ghci/scripts/T17403.script
new file mode 100644 (file)
index 0000000..ad0f9cd
--- /dev/null
@@ -0,0 +1,2 @@
+:load T17403
+:type +v f
diff --git a/testsuite/tests/ghci/scripts/T17403.stdout b/testsuite/tests/ghci/scripts/T17403.stdout
new file mode 100644 (file)
index 0000000..c543c3d
--- /dev/null
@@ -0,0 +1 @@
+f :: (() :: Constraint) => String
index 96ca2eb..ede2805 100755 (executable)
@@ -313,3 +313,4 @@ test('T15546', normal, ghci_script, ['T15546.script'])
 test('T16876', normal, ghci_script, ['T16876.script'])
 test('T17345', normal, ghci_script, ['T17345.script'])
 test('T17384', normal, ghci_script, ['T17384.script'])
+test('T17403', normal, ghci_script, ['T17403.script'])