[commit: packages/array] master: Add diagnostics to overflow errors (b8a6d31)

git at git.haskell.org git at git.haskell.org
Thu Feb 9 02:21:11 UTC 2017


Repository : ssh://git@git.haskell.org/array

On branch  : master
Link       : http://git.haskell.org/packages/array.git/commitdiff/b8a6d313a9f20b756fc90845fdd530927686257d

>---------------------------------------------------------------

commit b8a6d313a9f20b756fc90845fdd530927686257d
Author: Oleg Grenrus <oleg.grenrus at iki.fi>
Date:   Tue Feb 7 13:17:03 2017 +0200

    Add diagnostics to overflow errors


>---------------------------------------------------------------

b8a6d313a9f20b756fc90845fdd530927686257d
 Data/Array/Base.hs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Data/Array/Base.hs b/Data/Array/Base.hs
index 43963eb..3bf861f 100644
--- a/Data/Array/Base.hs
+++ b/Data/Array/Base.hs
@@ -1354,13 +1354,15 @@ bOOL_SCALE, bOOL_WORD_SCALE,
   wORD_SCALE, dOUBLE_SCALE, fLOAT_SCALE :: Int# -> Int#
 bOOL_SCALE n#
   | isTrue# (res# ># n#) = res#
-  | otherwise = error "Data.Array.Base.bOOL_SCALE: Overflow"
+  | otherwise = error $ "Data.Array.Base.bOOL_SCALE: Overflow; n: "
+    ++ show (I# n#) ++ ", res: " ++ show (I# n#)
   where
     !(I# last#) = SIZEOF_HSWORD * 8 - 1
     !res# = (n# +# last#) `uncheckedIShiftRA#` 3#
 bOOL_WORD_SCALE n#
   | isTrue# (res# ># n#) = res#
-  | otherwise = error "Data.Array.Base.bOOL_WORD_SCALE: Overflow"
+  | otherwise = error $ "Data.Array.Base.bOOL_WORD_SCALE: Overflow; n: "
+    ++ show (I# n#) ++ ", res: " ++ show (I# n#)
   where
     !(I# last#) = SIZEOF_HSWORD * 8 - 1
     !res# = bOOL_INDEX (n# +# last#)
@@ -1371,7 +1373,8 @@ fLOAT_SCALE  n# = safe_scale scale# n# where !(I# scale#) = SIZEOF_HSFLOAT
 safe_scale :: Int# -> Int# -> Int#
 safe_scale scale# n#
   | not overflow = res#
-  | otherwise    = error "Data.Array.Base.safe_scale: Overflow"
+  | otherwise    = error $ "Data.Array.Base.safe_scale: Overflow; scale: "
+    ++ show (I# scale#) ++ ", n: " ++ show (I# n#)
   where
     !res# = scale# *# n#
     !overflow = isTrue# (maxN# `divInt#` scale# <# n#)



More information about the ghc-commits mailing list