From 68f6b9c9f4693df6ae761dd2651d06913b355152 Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 24 Jul 2003 07:49:33 +0000 Subject: [PATCH] [project @ 2003-07-24 07:49:33 by simonpj] 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Text/PrettyPrint/HughesPJ.hs b/Text/PrettyPrint/HughesPJ.hs index 58f098b..6a95b4d 100644 --- a/Text/PrettyPrint/HughesPJ.hs +++ b/Text/PrettyPrint/HughesPJ.hs @@ -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) -- 1.7.10.4