Commit 4b9764db authored by Ryan Scott's avatar Ryan Scott Committed by Marge Bot
Browse files

Define a Quote IO instance

Fixes #18103.
parent c62271a2
Pipeline #18687 failed with stages
in 376 minutes and 27 seconds
......@@ -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" }
......
{-# LANGUAGE TemplateHaskellQuotes #-}
module T18103 where
import Language.Haskell.TH
ex :: IO [Dec]
ex = [d| foo x = x |]
......@@ -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 |]
......
......@@ -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, [''])
......
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