Splice singleton unboxed tuples correctly with Template Haskell
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 22 Aug 2016 14:39:12 +0000 (10:39 -0400)
committerRyan Scott <ryan.gl.scott@gmail.com>
Mon, 22 Aug 2016 14:39:13 +0000 (10:39 -0400)
Summary:
Previously, TH would implicitly remove the parentheses when splicing in
singleton unboxed tuple types (e.g., turning `(# Int #)` into `Int`). Luckily,
the fix is simply to delete some code.

Fixes #12513.

Test Plan: make test TEST=T12513

Reviewers: hvr, bgamari, austin, goldfire

Reviewed By: goldfire

Subscribers: thomie

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

GHC Trac Issues: #12513

compiler/hsSyn/Convert.hs
docs/users_guide/8.0.2-notes.rst
testsuite/tests/th/T12513.hs [new file with mode: 0644]
testsuite/tests/th/T12513.stderr [new file with mode: 0644]
testsuite/tests/th/all.T

index ad51f9d..ee1f106 100644 (file)
@@ -1134,9 +1134,7 @@ cvtTypeKind ty_str ty
              -> mk_apps (HsTyVar (noLoc (getRdrName (tupleTyCon Boxed n)))) tys'
            UnboxedTupleT n
              | length tys' == n         -- Saturated
-             -> if n==1 then return (head tys') -- Singleton tuples treated
-                                                -- like nothing (ie just parens)
-                        else returnL (HsTupleTy HsUnboxedTuple tys')
+             -> returnL (HsTupleTy HsUnboxedTuple tys')
              | otherwise
              -> mk_apps (HsTyVar (noLoc (getRdrName (tupleTyCon Unboxed n))))
                         tys'
index 39ad028..f75c684 100644 (file)
@@ -39,6 +39,10 @@ Template Haskell
    Template Haskell reified unboxed tuples as boxed tuples with twice their
    appropriate arity.)
 
+-  Splicing singleton unboxed tuple types (e.g., ``(# Int #)``) now works
+   correctly. Previously, Template Haskell would implicitly remove the
+   parentheses when splicing, which would turn ``(# Int #)`` into ``Int``.
+
 TODO FIXME Heading title
 ~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/testsuite/tests/th/T12513.hs b/testsuite/tests/th/T12513.hs
new file mode 100644 (file)
index 0000000..625e4c4
--- /dev/null
@@ -0,0 +1,12 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE UnboxedTuples #-}
+module T12513 where
+
+import Language.Haskell.TH.Lib
+import Language.Haskell.TH.Syntax
+
+f :: $([t| (# Int #) |]) -> Int
+f x = x
+
+g :: $(unboxedTupleT 1 `appT` conT ''Int) -> Int
+g x = x
diff --git a/testsuite/tests/th/T12513.stderr b/testsuite/tests/th/T12513.stderr
new file mode 100644 (file)
index 0000000..26a2dbb
--- /dev/null
@@ -0,0 +1,10 @@
+
+T12513.hs:9:7: error:
+    • Couldn't match expected type ‘Int’ with actual type ‘(# Int #)’
+    • In the expression: x
+      In an equation for ‘f’: f x = x
+
+T12513.hs:12:7: error:
+    • Couldn't match expected type ‘Int’ with actual type ‘(# Int #)’
+    • In the expression: x
+      In an equation for ‘g’: g x = x
index 5cece92..b05d601 100644 (file)
@@ -421,3 +421,4 @@ test('T12130', extra_clean(['T12130a.hi','T12130a.o']),
 test('T12403', omit_ways(['ghci']),
               compile_and_run, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T12407', omit_ways(['ghci']), compile, ['-v0'])
+test('T12513', omit_ways(['ghci']), compile_fail, ['-v0'])