Parenthesize pretty-printed equalities when necessary
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 11 May 2017 19:42:55 +0000 (15:42 -0400)
committerBen Gamari <ben@smart-cactus.org>
Thu, 11 May 2017 21:33:12 +0000 (17:33 -0400)
Fixes #13677 by parenthesizing equalities in a sufficiently high
pretty-printing context.

Test Plan: make test TEST=T13677

Reviewers: goldfire, austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13677

Differential Revision: https://phabricator.haskell.org/D3570

compiler/iface/IfaceType.hs
testsuite/tests/typecheck/should_fail/T13677.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T13677.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T

index 41cf4f6..eafd6dd 100644 (file)
@@ -979,7 +979,7 @@ pprTyTcApp' ctxt_prec tc tys dflags style
          -> text "(TypeError ...)"
 
        | Just doc <- ppr_equality tc (tcArgsIfaceTypes tys)
-         -> doc
+         -> maybeParen ctxt_prec TyConPrec doc
 
        | otherwise
          -> ppr_iface_tc_app ppr_ty ctxt_prec tc tys_wo_kinds
diff --git a/testsuite/tests/typecheck/should_fail/T13677.hs b/testsuite/tests/typecheck/should_fail/T13677.hs
new file mode 100644 (file)
index 0000000..f452a20
--- /dev/null
@@ -0,0 +1,11 @@
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE GADTs #-}
+module T13677 where
+
+import GHC.Exts (Constraint)
+
+data Dict a where
+  Dict :: a => Dict a
+
+foo :: Dict (Int ~ Int) => Int
+foo = undefined
diff --git a/testsuite/tests/typecheck/should_fail/T13677.stderr b/testsuite/tests/typecheck/should_fail/T13677.stderr
new file mode 100644 (file)
index 0000000..c29aba2
--- /dev/null
@@ -0,0 +1,4 @@
+
+T13677.hs:10:8: error:
+    • Expected a constraint, but ‘Dict (Int ~ Int)’ has kind ‘*’
+    • In the type signature: foo :: Dict (Int ~ Int) => Int
index 4a409e0..3875063 100644 (file)
@@ -438,3 +438,4 @@ test('T13506', normal, compile_fail, [''])
 test('T13611', expect_broken(13611), compile_fail, [''])
 test('T13320', normal, compile_fail, [''])
 test('T13640', normal, compile_fail, [''])
+test('T13677', normal, compile_fail, [''])