gren-lang / gren-lang/core

`Char.fromCode` throws a `RangeError` out of range, but its documentation says it returns U+FFFD

Open Beginner friendly
#149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
48
Forks
14
Avg merge
4h 14m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the _Char_fromCode implementation and its call to String.fromCodePoint, then compare the behavior with the documented Char.fromCode examples. Verify the reproduction for negative and above-range codepoints; done means those inputs return U+FFFD as documented while valid codepoints continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.