Bodigrim pushed to branch wip/better-error-for-chr at Glasgow Haskell Compiler / GHC
Commits:
-
87db1207
by Andrew Lelechenko at 2026-03-28T11:14:15+00:00
5 changed files:
- libraries/base/changelog.md
- libraries/base/tests/enum01.stdout
- libraries/base/tests/enum01.stdout-alpha-dec-osf3
- libraries/base/tests/enum01.stdout-ws-64
- libraries/ghc-internal/src/GHC/Internal/Char.hs
Changes:
| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | * Hide implementation details when throwing exceptions in throw and throwSTM. ([CLC proposal #387](https://github.com/haskell/core-libraries-committee/issues/387))
|
| 29 | 29 | * Change `hIsReadable` and `hIsWritable` such that they always throw a respective exception when encountering a closed or semi-closed handle, not just in the case of a file handle. ([CLC proposal #371](github.com/haskell/core-libraries-committee/issues/371))
|
| 30 | 30 | * Annotate `onException` continuation with `WhileHandling`. ([CLC Proposal #397](https://github.com/haskell/core-libraries-committee/issues/397))
|
| 31 | + * Improve error message for `Data.Char.chr`. ([CLC Proposal #384](https://github.com/haskell/core-libraries-committee/issues/384))
|
|
| 31 | 32 | |
| 32 | 33 | ## 4.22.0.0 *TBA*
|
| 33 | 34 | * Shipped with GHC 9.14.1
|
| ... | ... | @@ -81,7 +81,7 @@ Testing Enum Char: |
| 81 | 81 | pred (maxBound::Char) = '\1114110'
|
| 82 | 82 | pred (minBound::Char) = error "Prelude.Enum.Char.pred: bad argument"
|
| 83 | 83 | (map (toEnum::Int->Char) [123,ord (minBound::Char), ord(maxBound::Char)]) = "{\NUL\1114111"
|
| 84 | - (toEnum::Int->Char) (minBound::Int) = error "Prelude.chr: bad argument: (-2147483648)"
|
|
| 84 | + (toEnum::Int->Char) (minBound::Int) = error "Data.Char.chr: argument outside Unicode range: 0..1114111: (-2147483648)"
|
|
| 85 | 85 | (map fromEnum ['X',minBound,maxBound]) = [88,0,1114111]
|
| 86 | 86 | (take 7 ['\NUL' .. ]) = "\NUL\SOH\STX\ETX\EOT\ENQ\ACK"
|
| 87 | 87 | (take 7 ['\250' .. ]) = "\250\251\252\253\254\255\256"
|
| ... | ... | @@ -65,7 +65,7 @@ Testing Enum Char: |
| 65 | 65 | pred (maxBound::Char) = '\1114110'
|
| 66 | 66 | pred (minBound::Char) = error "Prelude.Enum.Char.pred: bad argument"
|
| 67 | 67 | (map (toEnum::Int->Char) [123,ord (minBound::Char), ord(maxBound::Char)]) = "{\NUL\1114111"
|
| 68 | - (toEnum::Int->Char) (minBound::Int) = error "Prelude.chr: bad argument"
|
|
| 68 | + (toEnum::Int->Char) (minBound::Int) = error "Data.Char.chr: argument outside Unicode range: 0..1114111:"
|
|
| 69 | 69 | (map fromEnum ['X',minBound,maxBound]) = [88,0,1114111]
|
| 70 | 70 | (take 7 ['\NUL' .. ]) = "\NUL\SOH\STX\ETX\EOT\ENQ\ACK"
|
| 71 | 71 | (take 7 ['\250' .. ]) = "\250\251\252\253\254\255\256"
|
| ... | ... | @@ -81,7 +81,7 @@ Testing Enum Char: |
| 81 | 81 | pred (maxBound::Char) = '\1114110'
|
| 82 | 82 | pred (minBound::Char) = error "Prelude.Enum.Char.pred: bad argument"
|
| 83 | 83 | (map (toEnum::Int->Char) [123,ord (minBound::Char), ord(maxBound::Char)]) = "{\NUL\1114111"
|
| 84 | - (toEnum::Int->Char) (minBound::Int) = error "Prelude.chr: bad argument: (-9223372036854775808)"
|
|
| 84 | + (toEnum::Int->Char) (minBound::Int) = error "Data.Char.chr: argument outside Unicode range: 0..1114111: (-9223372036854775808)"
|
|
| 85 | 85 | (map fromEnum ['X',minBound,maxBound]) = [88,0,1114111]
|
| 86 | 86 | (take 7 ['\NUL' .. ]) = "\NUL\SOH\STX\ETX\EOT\ENQ\ACK"
|
| 87 | 87 | (take 7 ['\250' .. ]) = "\250\251\252\253\254\255\256"
|
| ... | ... | @@ -12,7 +12,7 @@ module GHC.Internal.Char |
| 12 | 12 | |
| 13 | 13 | import GHC.Internal.Classes (eqChar, neChar)
|
| 14 | 14 | import GHC.Internal.Base (otherwise, (++))
|
| 15 | -import GHC.Internal.Err (errorWithoutStackTrace)
|
|
| 15 | +import GHC.Internal.Err (error)
|
|
| 16 | 16 | import GHC.Internal.Show
|
| 17 | 17 | import GHC.Internal.Prim (chr#, int2Word#, leWord#, Int#, Char#)
|
| 18 | 18 | import GHC.Internal.Types (Char(..), Int(..), isTrue#)
|
| ... | ... | @@ -29,4 +29,7 @@ safe_chr# i# |
| 29 | 29 | |
| 30 | 30 | {-# NOINLINE chr_error #-}
|
| 31 | 31 | chr_error :: Int# -> Char#
|
| 32 | -chr_error i# = errorWithoutStackTrace ("Prelude.chr: bad argument: " ++ showSignedInt (I# 9#) (I# i#) "") |
|
| 32 | +chr_error i# = error ("Data.Char.chr: argument outside Unicode range: 0..1114111: " ++ showSignedInt (I# 9#) (I# i#) "")
|
|
| 33 | +-- It's not really "Data.Char", but we assume that
|
|
| 34 | +-- the majority of users will import it from "base:Data.Char"
|
|
| 35 | +-- and not from "ghc-internal:GHC.Internal.Char". |