[project @ 2003-07-24 07:49:33 by simonpj]
authorsimonpj <unknown>
Thu, 24 Jul 2003 07:49:33 +0000 (07:49 +0000)
committersimonpj <unknown>
Thu, 24 Jul 2003 07:49:33 +0000 (07:49 +0000)
A gross hack to stop the pretty-printer going into an infinite loop.
What happens is that 'indent' is given a negative number, and that
made it loop.  This patch checks for the negative case, so at least
it doesn't loop -- but I don't understand why the indent ever goes negative,
so there's still something wrong here.

Text/PrettyPrint/HughesPJ.hs

index 58f098b..6a95b4d 100644 (file)
@@ -881,6 +881,15 @@ indent n | n >= 8 = '\t' : indent (n - 8)
 multi_ch 0 ch = ""
 multi_ch n       ch = ch : multi_ch (n - 1) ch
 
-spaces 0 = ""
-spaces n       = ' ' : spaces (n - 1)
+-- (spaces n) generates a list of n spaces
+--
+-- It should never be called with 'n' < 0, but that can happen for reasons I don't understand
+-- Here's a test case:
+--     ncat x y = nest 4 $ cat [ x, y ]
+--     d1 = foldl1 ncat $ take 50 $ repeat $ char 'a'
+--     d2 = parens $  sep [ d1, text "+" , d1 ]
+--     main = print d2
+-- I don't feel motivated enough to find the Real Bug, so meanwhile we just test for n<=0
+spaces n | n <= 0    = ""
+        | otherwise = ' ' : spaces (n - 1)