[GHC] #14302: ghc panic on simple program

GHC ghc-devs at haskell.org
Sun Oct 1 18:24:19 UTC 2017


#14302: ghc panic on simple program
-------------------------------------+-------------------------------------
           Reporter:  aberent        |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Compile-time
  Unknown/Multiple                   |  crash or panic
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I am experimenting with Haskell, and am attempting to write a simple maze
 solver. ghci gives meaningful errors for it, and doesn't crash, but ghc
 gives


 {{{
 ~/haskell/course$ ghc tiltmaze.hs
 [1 of 1] Compiling Main             ( tiltmaze.hs, tiltmaze.o )
 ghc: panic! (the 'impossible' happened)
   (GHC version 8.0.2 for x86_64-unknown-linux):
         initTc: unsolved constraints
   WC {wc_insol =
         [W] m'_a5Wy :: t_a5Wx[tau:1] (CHoleCan: m')
         [W] sx'_a5WB :: t_a5WA[tau:1] (CHoleCan: sx')
         [W] sy'_a5WE :: t_a5WD[tau:1] (CHoleCan: sy')}

 Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
 }}}

 The code is:


 {{{
 import Data.Sequence as Sequence
 -- A maze is a grid of empty cells and walls
 -- true means wall
 data Maze = Seq (Seq Bool)

 data Direction = North | South | East | West
 directions = [North, South, East, West]

 step :: Direction -> Int -> Int -> (Int, Int)
 step d x y
   | North = (x, y-1)
   | South = (x, y+1)
   | East = (x+1, y)
   | West = (x-1, y)

 solve :: Maze -> Int -> Int -> Int -> Int -> Bool
 solve m sx sy tx ty
   | sx == tx && sy == ty = True
   | otherwise =
     let solved m x y d
           | x' < 0 = False
           | y' < 0 = False
           | x' >= Sequence.length m  = False
           | y' >= Sequence.length $ m `index` x' = False
           | not ((m `index` x') `index` y') = False
           | otherwise = solve m' x' y' tx ty
               where (x', y') = step d
                     m' = update y False (m `index` x)
       in any (solved m' sx' sy') directions

 }}}

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


More information about the ghc-tickets mailing list