Commit fb0d87f1 authored by Ryan Scott's avatar Ryan Scott

Splice singleton unboxed tuples correctly with Template Haskell

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
parent f9aa996f
......@@ -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'
......
......@@ -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
~~~~~~~~~~~~~~~~~~~~~~~~
......
{-# 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
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
......@@ -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'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment