Found against: gren 0.6.6, gren-lang/core 7.4.2, node 2
Summary
Char.fromCode : Int -> Char's doc comment says what a number outside Unicode's
range of codepoints returns:
The full range of unicode is from 0 to 0x10FFFF. With numbers outside that
range, you get [the replacement character][fffd].
with fromCode -1 == '�' as its own example. It throws instead:
_Char_fromCode is __Utils_chr(String.fromCodePoint(code)), and
String.fromCodePoint raises a RangeError below 0 and above 0x10FFFF.
The documentation is accurate about Elm, which the module was derived from —
elm/core's kernel guards the range and returns U+FFFD — and Gren's rewrite to
String.fromCodePoint dropped the guard along with the surrogate arithmetic it
replaced. Nothing in the doc comment was changed, so the two have disagreed
since.
Reproduction
> Char.fromCode 65
'A' : Char
> Char.toCode (Char.fromCode 0xD800)
55296 : Int
> Char.fromCode -1
RangeError: Invalid code point -1
> Char.fromCode 0x110000
RangeError: Invalid code point 1114112
| expression |
documented |
actual |
Char.fromCode 65 |
'A' |
'A' |
Char.fromCode 0xD800 |
not mentioned |
a Char holding a lone surrogate |
Char.fromCode -1 |
'\u{FFFD}' |
RangeError: Invalid code point -1 |
Char.fromCode 0x110000 |
'\u{FFFD}' |
RangeError: Invalid code point 1114112 |
Found against:
gren0.6.6,gren-lang/core7.4.2, node 2Summary
Char.fromCode : Int -> Char's doc comment says what a number outside Unicode'srange of codepoints returns:
with
fromCode -1 == '�'as its own example. It throws instead:_Char_fromCodeis__Utils_chr(String.fromCodePoint(code)), andString.fromCodePointraises aRangeErrorbelow0and above0x10FFFF.The documentation is accurate about Elm, which the module was derived from —
elm/core's kernel guards the range and returns U+FFFD — and Gren's rewrite toString.fromCodePointdropped the guard along with the surrogate arithmetic itreplaced. Nothing in the doc comment was changed, so the two have disagreed
since.
Reproduction
Char.fromCode 65'A''A'Char.fromCode 0xD800Charholding a lone surrogateChar.fromCode -1'\u{FFFD}'RangeError: Invalid code point -1Char.fromCode 0x110000'\u{FFFD}'RangeError: Invalid code point 1114112