Commit 00c8d4d5 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by Ben Gamari

Fix #10596 by looking up 'Int' not 'Maybe Int' in the map.


Test Plan: validate

Reviewers: goldfire, austin, simonpj, bgamari

Reviewed By: bgamari

Subscribers: simonpj, rwbarton, thomie, bgamari

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

GHC Trac Issues: #10596
parent d03bcfaa
......@@ -6,7 +6,11 @@
TcSplice: Template Haskell splices
-}
{-# LANGUAGE CPP, FlexibleInstances, MagicHash, ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module TcSplice(
......@@ -106,7 +110,7 @@ import GHC.Desugar ( AnnotationWrapper(..) )
import qualified Data.Map as Map
import Data.Dynamic ( fromDynamic, toDyn )
import Data.Typeable ( typeOf )
import Data.Typeable ( typeOf, Typeable )
import Data.Data (Data)
import GHC.Exts ( unsafeCoerce# )
#endif
......@@ -833,11 +837,14 @@ instance TH.Quasi (IOEnv (Env TcGblEnv TcLclEnv)) where
th_modfinalizers_var <- fmap tcg_th_modfinalizers getGblEnv
updTcRef th_modfinalizers_var (\fins -> fin:fins)
qGetQ :: forall a. Typeable a => IOEnv (Env TcGblEnv TcLclEnv) (Maybe a)
qGetQ = do
th_state_var <- fmap tcg_th_state getGblEnv
th_state <- readTcRef th_state_var
let x = Map.lookup (typeOf x) th_state >>= fromDynamic
return x
-- See #10596 for why we use a scoped type variable here.
-- ToDo: convert @undefined :: a@ to @proxy :: Proxy a@ when
-- we drop support for GHC 7.6.
return (Map.lookup (typeOf (undefined :: a)) th_state >>= fromDynamic)
qPutQ x = do
th_state_var <- fmap tcg_th_state getGblEnv
......
{-# LANGUAGE TemplateHaskell #-}
module T10596 where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
do
putQ (100 :: Int)
x <- (getQ :: Q (Maybe Int))
-- It should print "Just 100"
runIO $ print x
return []
......@@ -345,3 +345,4 @@ test('T10047', normal, ghci_script, ['T10047.script'])
test('T10019', normal, ghci_script, ['T10019.script'])
test('T10279', normal, compile_fail, ['-v0'])
test('T10306', normal, compile, ['-v0'])
test('T10596', normal, compile, ['-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