[Git][ghc/ghc][master] Define a Quote IO instance

Marge Bot gitlab at gitlab.haskell.org
Tue Apr 28 19:40:14 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
4b9764db by Ryan Scott at 2020-04-28T15:40:04-04:00
Define a Quote IO instance

Fixes #18103.

- - - - -


4 changed files:

- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- + testsuite/tests/quotes/T18103.hs
- testsuite/tests/quotes/TH_localname.stderr
- testsuite/tests/quotes/all.T


Changes:

=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -125,8 +125,7 @@ class (MonadIO m, MonadFail m) => Quasi m where
 -----------------------------------------------------
 
 instance Quasi IO where
-  qNewName s = do { n <- atomicModifyIORef' counter (\x -> (x + 1, x))
-                  ; pure (mkNameU s n) }
+  qNewName = newNameIO
 
   qReport True  msg = hPutStrLn stderr ("Template Haskell error: " ++ msg)
   qReport False msg = hPutStrLn stderr ("Template Haskell error: " ++ msg)
@@ -153,6 +152,13 @@ instance Quasi IO where
   qIsExtEnabled _       = badIO "isExtEnabled"
   qExtsEnabled          = badIO "extsEnabled"
 
+instance Quote IO where
+  newName = newNameIO
+
+newNameIO :: String -> IO Name
+newNameIO s = do { n <- atomicModifyIORef' counter (\x -> (x + 1, x))
+                 ; pure (mkNameU s n) }
+
 badIO :: String -> IO a
 badIO op = do   { qReport True ("Can't do `" ++ op ++ "' in the IO monad")
                 ; fail "Template Haskell failure" }


=====================================
testsuite/tests/quotes/T18103.hs
=====================================
@@ -0,0 +1,7 @@
+{-# LANGUAGE TemplateHaskellQuotes #-}
+module T18103 where
+
+import Language.Haskell.TH
+
+ex :: IO [Dec]
+ex = [d| foo x = x |]


=====================================
testsuite/tests/quotes/TH_localname.stderr
=====================================
@@ -7,8 +7,10 @@ TH_localname.hs:3:11: error:
         x :: t0 -> m0 Language.Haskell.TH.Syntax.Exp
           (bound at TH_localname.hs:3:1)
       Probable fix: use a type annotation to specify what ‘m0’ should be.
-      These potential instance exist:
-        one instance involving out-of-scope types
+      These potential instances exist:
+        instance Language.Haskell.TH.Syntax.Quote IO
+          -- Defined in ‘Language.Haskell.TH.Syntax’
+        ...plus one instance involving out-of-scope types
         (use -fprint-potential-instances to see them all)
     • In the expression:
         [| y |]


=====================================
testsuite/tests/quotes/all.T
=====================================
@@ -17,6 +17,7 @@ test('T9824', normal, compile, ['-v0'])
 test('T10384', normal, compile_fail, [''])
 test('T16384', req_th, compile, [''])
 test('T17857', normal, compile, [''])
+test('T18103', normal, compile, [''])
 
 test('TH_tf2', normal, compile, ['-v0'])
 test('TH_ppr1', normal, compile_and_run, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4b9764db7c190de377c06dfc71bfe6e4b37c7eb0

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4b9764db7c190de377c06dfc71bfe6e4b37c7eb0
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200428/5d8bd715/attachment-0001.html>


More information about the ghc-commits mailing list