diff options
author | RyanGlScott <ryan.gl.scott@ku.edu> | 2015-07-17 00:05:14 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-07-17 00:08:10 +0200 |
commit | 2c9de9c9a3df8e855c883139b0cb2fd41801bd67 (patch) | |
tree | 537691587672cacd63f077ec38d36094e7e5fb59 /testsuite | |
parent | 2c5c29722c78e089eda0baa7ff89154b58f23165 (diff) | |
download | haskell-2c9de9c9a3df8e855c883139b0cb2fd41801bd67.tar.gz |
Handle Char#, Addr# in TH quasiquoter (fixes #10620)
DsMeta does not attempt to handle quasiquoted Char# or Addr# values,
which causes expressions like `$([| 'a'# |])` or `$([| "abc"# |])` to
fail
with an `Exotic literal not (yet) handled by Template Haskell` error.
To fix this, the API of `template-haskell` had to be changed so that
`Lit`
now has an extra constructor `CharPrimL` (a `StringPrimL` constructor
already
existed, but it wasn't used). In addition, `DsMeta` has to manipulate
`CoreExpr`s directly that involve `Word8`s. In order to do this,
`Word8` had
to be added as a wired-in type to `TysWiredIn`.
Actually converting from `HsCharPrim` and `HsStringPrim` to `CharPrimL`
and
`StringPrimL`, respectively, is pretty straightforward after that, since
both `HsCharPrim` and `CharPrimL` use `Char` internally, and
`HsStringPrim`
uses a `ByteString` internally, which can easily be converted to
`[Word8]`,
which is what `StringPrimL` uses.
Reviewers: goldfire, austin, simonpj, bgamari
Reviewed By: simonpj, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1054
GHC Trac Issues: #10620
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/th/T10620.hs | 9 | ||||
-rw-r--r-- | testsuite/tests/th/T10620.stdout | 2 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/testsuite/tests/th/T10620.hs b/testsuite/tests/th/T10620.hs new file mode 100644 index 0000000000..3fe2519891 --- /dev/null +++ b/testsuite/tests/th/T10620.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE MagicHash, TemplateHaskell #-} +module Main where + +import Language.Haskell.TH + +main :: IO () +main = do + putStrLn $([| 'a'# |] >>= stringE . show) + putStrLn $([| "abc"# |] >>= stringE . show) diff --git a/testsuite/tests/th/T10620.stdout b/testsuite/tests/th/T10620.stdout new file mode 100644 index 0000000000..a0415d2442 --- /dev/null +++ b/testsuite/tests/th/T10620.stdout @@ -0,0 +1,2 @@ +LitE (CharPrimL 'a') +LitE (StringPrimL [97,98,99]) diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index 6c2453f488..55627f05b5 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -345,3 +345,4 @@ test('T10019', normal, ghci_script, ['T10019.script']) test('T10279', normal, compile_fail, ['-v0']) test('T10306', normal, compile, ['-v0']) test('T10596', normal, compile, ['-v0']) +test('T10620', normal, compile_and_run, ['-v0']) |