[GHC] #1176: Infinite loop when printing error message

GHC trac at galois.com
Thu Mar 1 06:49:18 EST 2007


#1176: Infinite loop when printing error message
---------------------------------------+------------------------------------
 Reporter:  Paul_Berry at alumni.hmc.edu  |          Owner:          
     Type:  bug                        |         Status:  new     
 Priority:  low                        |      Milestone:  _|_     
Component:  Compiler                   |        Version:  6.6     
 Severity:  normal                     |     Resolution:          
 Keywords:                             |     Difficulty:  Unknown 
 Testcase:  tcfail177                  |   Architecture:  Multiple
       Os:  Multiple                   |  
---------------------------------------+------------------------------------
Changes (by simonpj):

  * milestone:  => _|_
  * priority:  normal => low
  * testcase:  => tcfail177

Comment:

 This is a bug in the pretty-printer.  Here's a much smaller program that
 demonstrates the problem:
 {{{
 module Foo5 where

 -- The more infix ops we have, the worse fsep works

 allTests :: Bool
 allTests :: Bool
 allTests = foo
            [a ~?= b
            ,"Three" ~?= "3"
            ,"Four" ~?= "4"
            ,"Five" ~?= "5"
            ,"Five" ~?= "5"
            ,"Five" ~?= "5"
            ,"Two", "Two", "Two"
            ,"Two", "Two", "Two"
            ,"Two", "Two", "Two"
            ,"Two", "Two", "Two"
            ,"Two", "Two", "Two"
            ,"Two", "Two", "Two"]

 a=""
 b=""

 (~?=) :: a -> a -> Bool
 (~?=) = error "urk"

 foo :: a -> Int
 foo x = 0
 }}}
 This gives the message:
 {{{
 Foo5.hs:15:12:
     Couldn't match expected type `Bool' against inferred type `[Char]'
     In the expression: "Two"
     In the first argument of `foo', namely
         `[a ~?= b, "Three" ~?= "3", "Four" ~?= "4", "Five" ~?= "5",
     "Five" ~?= "5", "Five" ~?= "5", "Two", "Two", "Two", "Two", "Two",
 "Two", "Two", "Two", "Two", "Two", "Two", "Two", "Two", "Two",
 "Two", "Two", "Two", "Two"]'
     In the expression:
         foo
           [a ~?= b, "Three" ~?= "3", "Four" ~?= "4", "Five" ~?= "5",
      "Five" ~?= "5", "Five" ~?= "5", "Two", "Two", "Two", "Two", "Two",
  "Two", "Two", "Two", "Two", "Two", "Two", "Two", "Two", "Two",
  "Two", "Two", "Two", "Two"]
 }}}
 Notice the way that the layout is wrong: the lines are not indented
 enough.  If you add one more line containing the infix operator, the
 infinite loop happens.

 What is happening is that when the indent goes negative, the space
 generator goes wild.

 I've fixed that that, so it'll put zero spaces in when the indent is
 negative.

 But there's still a problem: the indent should not be going negative.  The
 pretty-printing library could really do with someone looking at it
 carefully.  We already have an open bug on that: #669, so I'm going to
 leave this one open because GHC's Pretty module isn't the same as the
 `Text.PrettyPrint.HughesPJ` module.

 So infinite loop is fixed, but the bad formatting remains.  I've added a
 test, tcfail177.

 Please merge the fix the STABLE 6.6 branch:
 {{{
 Thu Mar  1 11:45:13 GMT 2007  simonpj at microsoft.com
   * Do not go into an infinite loop when pretty-printer
              finds a negative indent (Trac #1176)
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1176>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list