Typeable: Only render saturated tuple types with tuple syntax
authorBen Gamari <bgamari.foss@gmail.com>
Mon, 15 Oct 2018 17:36:16 +0000 (13:36 -0400)
committerBen Gamari <ben@smart-cactus.org>
Mon, 15 Oct 2018 21:41:48 +0000 (17:41 -0400)
This isn't as efficient as it could be since it needs to compute the
kind of the type. However, this is `show` so there shouldn't be any
particular expectation of speed.

Fixes #14341.

Test Plan: Validate

Reviewers: hvr

Subscribers: monoidal, rwbarton, carter

GHC Trac Issues: #14341

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

libraries/base/Data/Typeable/Internal.hs
testsuite/tests/typecheck/should_run/T14341.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_run/T14341.stdout [new file with mode: 0644]
testsuite/tests/typecheck/should_run/all.T

index 0d4fc82..06d225a 100644 (file)
@@ -773,7 +773,11 @@ showTypeable _ TrType = showChar '*'
 showTypeable _ rep
   | isListTyCon tc, [ty] <- tys =
     showChar '[' . shows ty . showChar ']'
-  | isTupleTyCon tc =
+
+    -- Take care only to render saturated tuple tycon applications
+    -- with tuple notation (#14341).
+  | isTupleTyCon tc,
+    Just _ <- TrType `eqTypeRep` typeRepKind rep =
     showChar '(' . showArgs (showChar ',') tys . showChar ')'
   where (tc, tys) = splitApps rep
 showTypeable _ (TrTyCon {trTyCon = tycon, trKindVars = []})
diff --git a/testsuite/tests/typecheck/should_run/T14341.hs b/testsuite/tests/typecheck/should_run/T14341.hs
new file mode 100644 (file)
index 0000000..72d2f63
--- /dev/null
@@ -0,0 +1,9 @@
+{-# LANGUAGE TypeApplications #-}
+
+import Type.Reflection
+
+main :: IO ()
+main = do
+    print $ typeRep @((,,))
+    print $ typeRep @((,,) Int)
+    print $ typeRep @((,,) Int Int Int)
diff --git a/testsuite/tests/typecheck/should_run/T14341.stdout b/testsuite/tests/typecheck/should_run/T14341.stdout
new file mode 100644 (file)
index 0000000..ea3d344
--- /dev/null
@@ -0,0 +1,3 @@
+(,,)
+(,,) Int
+(Int,Int,Int)
\ No newline at end of file
index a96c2b7..4f75c70 100755 (executable)
@@ -136,3 +136,4 @@ test('T13838', [exit_code(1), omit_ways(['ghci'])], compile_and_run, ['-fdefer-t
 test('T14218', normal, compile_and_run, [''])
 test('T14236', normal, compile_and_run, [''])
 test('T14925', normal, compile_and_run, [''])
+test('T14341', normal, compile_and_run, [''])