From a2d98d0708e4c0dd132ef562fb025f6bf33d8c00 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 18 Apr 2007 13:38:24 +0000 Subject: [PATCH] handle out-of-range lines in :break more gracefully --- compiler/ghci/InteractiveUI.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index a1aaa6a..c83e4df 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -1573,10 +1573,12 @@ findBreakAndSet mod lookupTickTree = do -- - the rightmost subexpression enclosing the specified line -- findBreakByLine :: Int -> TickArray -> Maybe (BreakIndex,SrcSpan) -findBreakByLine line arr = - listToMaybe (sortBy leftmost complete) `mplus` - listToMaybe (sortBy leftmost incomplete) `mplus` - listToMaybe (sortBy rightmost ticks) +findBreakByLine line arr + | not (inRange (bounds arr) line) = Nothing + | otherwise = + listToMaybe (sortBy leftmost complete) `mplus` + listToMaybe (sortBy leftmost incomplete) `mplus` + listToMaybe (sortBy rightmost ticks) where ticks = arr ! line @@ -1587,8 +1589,10 @@ findBreakByLine line arr = where ends_here (nm,span) = srcSpanEndLine span == line findBreakByCoord :: (Int,Int) -> TickArray -> Maybe (BreakIndex,SrcSpan) -findBreakByCoord (line, col) arr = - listToMaybe (sortBy rightmost contains) +findBreakByCoord (line, col) arr + | not (inRange (bounds arr) line) = Nothing + | otherwise = + listToMaybe (sortBy rightmost contains) where ticks = arr ! line -- 1.7.10.4