You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2a3c984
Browse filesBrowse the repository at this point in the historyBrowse files
`char` was a private abbreviation of `int`: a char could be coerced to an
int with `:>`, but an int could not be used as a char. It is now a plain
alias, so char literals and ints mix freely, including in one `switch`.
Pattern matching treats a char constant and an int constant with the same
value as the same constant, for exhaustiveness, unused cases and switch
compilation. Char literals keep their spelling in generated JavaScript
comments and in warning examples. First step of #7028.
Example (rescript):
let f = x =>
switch x {
| '\000' .. '\255' => 0
| 'ō' => 2
| _ => 3
}
Before (js):
function f(x) {
if (x !== 333) {
if (x >= 256) {
return 3;
} else {
return 0;
}
} else {
return 2;
}
}
After (js):
function f(x) {
if (x >= 256) {
if (x !== 333) {
return 3;
} else {
return 2;
}
} else if (x >= 0) {
return 0;
} else {
return 3;
}
}
Source: tests/tests/src/string_unicode_test.mjs in the diff (the range starts
at code point 0, written as a literal NUL character in the test).
Review: Why keep `Const_char` instead of typing char literals as ints? It
keeps the `/* 'a' */97` comments in the JavaScript and the char spelling in
warnings such as "for example: | '\x00'".
Review: Why do char switches now use int32 bounds instead of 0..max_int? A
char can now hold any int, including negative ones, so a switch can no longer
assume `x >= 0`. Two committed snapshots change for that reason.
Review: Do integer range patterns such as `1 .. 5` work now? No, they still
report `Invalid_interval`. Char ranges expand to one case per value, which
does not scale to arbitrary ints; that needs interval patterns of their own.
Area: typechecker lambda analysis tests
Output: changed tests/tests/src/adt_optimize_test.mjs and
string_unicode_test.mjs, char switches whose range starts at '\000' now
send negative values to the default case
Formatting: unchanged
Formats: none
PPX: unchanged
Editor: pipe completion on a `char` value offers `Int` functions; it offered
none before (tests/analysis_tests/tests/src/CompletionChar.res)
Errors: ERROR_VARIANTS.md warnings section lists the two new warning 8 and 11
fixtures
Tests: +tests/tests/src/char_int_alias_test.res
+tests/analysis_tests/tests/src/CompletionChar.res
+tests/build_tests/super_errors/fixtures/warning_8_char_int_patterns.res
+tests/build_tests/super_errors/fixtures/warning_11_equivalent_char_int_patterns.res
~tests/tests/src/adt_optimize_test.mjs ~tests/tests/src/string_unicode_test.mjs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo
Signed-off-by: Christoph Knittel <ck@cca.io>
"value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"
18
+
},
19
+
"kind": 12,
20
+
"label": "Int.toStringWithRadix",
21
+
"tags": [ 1 ]
22
+
},
23
+
{
24
+
"detail": "(int, ~radix: int=?) => string",
25
+
"documentation": {
26
+
"kind": "markdown",
27
+
"value": "\n`toString(n, ~radix=?)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toString(1000) // \"1000\"\nInt.toString(-1000) // \"-1000\"\nInt.toString(6, ~radix=2) // \"110\"\nInt.toString(373592855, ~radix=16) // \"16449317\"\nInt.toString(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"
0 commit comments