Make chr say what its argument was, if it's a bad argument
authorIan Lynagh <igloo@earth.li>
Sat, 18 Jul 2009 15:10:49 +0000 (15:10 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 18 Jul 2009 15:10:49 +0000 (15:10 +0000)
GHC/Base.lhs
GHC/Show.lhs-boot [new file with mode: 0644]

index 3806d78..449a861 100644 (file)
@@ -101,6 +101,7 @@ import GHC.Classes
 import GHC.Generics
 import GHC.Ordering
 import GHC.Prim
+import {-# SOURCE #-} GHC.Show
 import {-# SOURCE #-} GHC.Err
 
 -- These two are not strictly speaking required by this module, but they are
@@ -535,8 +536,10 @@ instance Ord Char where
 
 -- | The 'Prelude.toEnum' method restricted to the type 'Data.Char.Char'.
 chr :: Int -> Char
-chr (I# i#) | int2Word# i# `leWord#` int2Word# 0x10FFFF# = C# (chr# i#)
-            | otherwise                                  = error "Prelude.chr: bad argument"
+chr i@(I# i#)
+ | int2Word# i# `leWord#` int2Word# 0x10FFFF# = C# (chr# i#)
+ | otherwise
+    = error ("Prelude.chr: bad argument: " ++ showSignedInt (I# 9#) i "")
 
 unsafeChr :: Int -> Char
 unsafeChr (I# i#) = C# (chr# i#)
diff --git a/GHC/Show.lhs-boot b/GHC/Show.lhs-boot
new file mode 100644 (file)
index 0000000..b01d165
--- /dev/null
@@ -0,0 +1,10 @@
+\begin{code}
+{-# OPTIONS_GHC -XNoImplicitPrelude #-}
+
+module GHC.Show (showSignedInt) where
+
+import GHC.Types
+
+showSignedInt :: Int -> Int -> [Char] -> [Char]
+\end{code}
+