Permalink
Browse files

Fix data constructor lookup for template-haskell-2.7. (Use lookupValu…

…eName)
  • Loading branch information...
1 parent c792d97 commit 412367e8b4baf22fa7569bb984b6f3d11e09cc54 @reinerp committed Mar 29, 2012
Showing with 11 additions and 4 deletions.
  1. +9 −2 Control/Applicative/QQ/ADo.hs
  2. +2 −2 applicative-quoters.cabal
@@ -1,4 +1,4 @@
-{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TemplateHaskell, CPP #-}
-- | Applicative do. Philippa Cowderoy's idea, some explanations due Edward
-- Kmett
@@ -69,7 +69,8 @@ import Data.Data (cast, gmapQ)
-- $caveats
--
--- Template Haskell is currently unable to reliably look up constructor names
+-- Versions of Template Haskell shipped prior to GHC 7.4 are unable
+-- to reliably look up constructor names
-- just from a string: if there is a type with the same name, it will
-- return information for that instead. This means that the safe version of
-- 'ado' is prone to failure where types and values share names. It tries to
@@ -162,6 +163,12 @@ failingPattern pat = case pat of
singleCon :: Name -> Q Bool
singleCon n = do
+#if MIN_VERSION_template_haskell(2,7,0)
+ n' <- lookupValueName (show n)
+ n <- case n' of
+ Just n -> return n
+ Nothing -> fail $ "Data constructor " ++ show n ++ " not in scope"
+#endif
info <- reify n
-- This covers the common case of a data type with one of the
-- constructors being named the same as the type, but fails if there
@@ -25,9 +25,9 @@ Library
Control.Applicative.QQ.Idiom
Build-depends:
- base >= 4 && < 4.5,
+ base >= 4 && < 4.6,
haskell-src-meta >= 0.2 && < 0.6,
- template-haskell >= 2.4 && < 2.7
+ template-haskell >= 2.4 && < 2.8
-- We disable the missing-fields warning because not only do quoteType
-- and quoteDec make no sense in this context, we can't initialise them

0 comments on commit 412367e

Please sign in to comment.