Skip to content

Better error message from Data.Char.chr #384

@Bodigrim

Description

@Bodigrim

(Previously discussed at https://gitlab.haskell.org/ghc/ghc/-/issues/21468)

At the moment Data.Char.chr is implemented as follows:

chr :: Int -> Char
chr i@(I# i#)
 | isTrue# (int2Word# i# `leWord#` 0x10FFFF##) = C# (chr# i#)
 | otherwise
    = errorWithoutStackTrace ("Prelude.chr: bad argument: " ++ showSignedInt (I# 9#) i "")

The error message is terrible: chr actually is not exported from Prelude and it would be nice to explain why exactly the argument is bad (that's because it is outside of Unicode range). I propose to change it to:

 | otherwise
    = error ("Argument of Data.Char.chr is outside of the Unicode range 0..0x10FFFF: " ++ showSignedInt (I# 9#) i "")

This also switches errorWithoutStackTrace to error: even while there is no HasCallStack, let's at least not suppress a call stack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaits-mergeApproved, but MR is still unmerged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions