core
core copied to clipboard
`Char::from_int` is unsafe
This code will crash:
fn init {
let a = from_int(-1)
println(a.to_string())
}
The Char::from_int is a primitive %char_from_int, which is an unsafe %identity.
pub fn Char::from_int(val : Int) -> Char = "%char_from_int"
We should verify the input similar to UChar.of_int in OCaml.
UChar.of_int will Raises Invalid_argument if i does not satisfy Uchar.is_valid.
is_valid n is true iff n is a Unicode scalar value (i.e. in the ranges 0x0000...0xD7FF or 0xE000...0x10FFFF).
So should it also raise exception?
#338
So should it also raise exception?
Like the APIs List::head/List::unsafe_head and Queue::peek/Queue::unsafe_peek, returning Option[Char] and providing an unchecked version is sufficient for me.