summaryrefslogtreecommitdiff
path: root/compiler/hsSyn
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2009-10-20 07:26:16 +0000
committersimonpj@microsoft.com <unknown>2009-10-20 07:26:16 +0000
commitfb02349ca1daf3eaedeff076bf7cedb5923b82f7 (patch)
tree6a2b73db0f3425e9cb67965aba06a55250a58c12 /compiler/hsSyn
parentf84a0b7028424ea167658c06e75e871198371f00 (diff)
downloadhaskell-fb02349ca1daf3eaedeff076bf7cedb5923b82f7.tar.gz
Fix Trac #3600: Template Haskell bug in Convert
This bug was introduced when I added an optimisation, described in Note [Converting strings] in Convert.lhs. It was treating *all* empty lists as strings, not just string-typed ones! The fix is easy. Pls MERGE to stable branch.
Diffstat (limited to 'compiler/hsSyn')
-rw-r--r--compiler/hsSyn/Convert.lhs14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/hsSyn/Convert.lhs b/compiler/hsSyn/Convert.lhs
index b87c18c56d..56ec2d763d 100644
--- a/compiler/hsSyn/Convert.lhs
+++ b/compiler/hsSyn/Convert.lhs
@@ -568,10 +568,16 @@ if it isn't a literal string
allCharLs :: [TH.Exp] -> Maybe String
-- Note [Converting strings]
-allCharLs (LitE (CharL c) : xs)
- | Just cs <- allCharLs xs = Just (c:cs)
-allCharLs [] = Just []
-allCharLs _ = Nothing
+-- NB: only fire up this setup for a non-empty list, else
+-- there's a danger of returning "" for [] :: [Int]!
+allCharLs xs
+ = case xs of
+ LitE (CharL c) : ys -> go [c] ys
+ _ -> Nothing
+ where
+ go cs [] = Just (reverse cs)
+ go cs (LitE (CharL c) : ys) = go (c:cs) ys
+ go _ _ = Nothing
cvtLit :: Lit -> CvtM HsLit
cvtLit (IntPrimL i) = do { force i; return $ HsIntPrim i }