Repository navigation
Make char an alias of int - #8892
Conversation
|
@codex review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8892 +/- ##
=======================================
Coverage 81.04% 81.05%
=======================================
Files 455 455
Lines 63508 63509 +1
=======================================
+ Hits 51469 51475 +6
+ Misses 12039 12034 -5
🚀 New features to boost your workflow:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8892 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
8b63ce5 to
001621d
Compare
`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) 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>
`Primitive_string_extern.getChar` returned `option<char>`; it returns `option<int>` now that `char` is an alias of `int`, which leaves no use of `char` in the runtime. The generated JavaScript is unchanged. Area: runtime Output: unchanged Tests: none, because the type is an alias of the old one and the output is unchanged 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>
001621d to
eaf8b90
Compare
First step of #7028.
charwas a private abbreviation ofint: 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 oneswitch:reactioncompiles to:Pattern matching treats a char constant and an int constant with the same value as the same constant (
Parmatch.const_compare/const_key) for exhaustiveness checks, unused-case checks, and switch compilation. Char literals keep their/* 'a' */97comments in the JS and their char spelling in warning examples.Switch bounds: char switches use int32 bounds instead of
0..max_int, because acharcan now be negative. A switch whose range starts at'\000'therefore gets an extrax >= 0check in the output. Before, it was skipped because chars were never negative. This costs at most one more comparison per path, and it changes two snapshots (adt_optimize_test.mjs,string_unicode_test.mjs). Other char ranges already checked both bounds, so their output is unchanged. For example, instring_unicode_test.mjs:Runtime:
Primitive_string_extern.getChar(codePointAt) now returnsoption<int>instead ofoption<char>, so the runtime no longer useschar. The generated JS is unchanged.Editor: pipe completion on a
charvalue now offersIntfunctions. It previously offered none, because it looked in the removedStdlib.Charmodule and its type filter treatedcharandintas different types.Not included: integer range patterns (
1 .. 5) still reportInvalid_intervalhere. They come later in this stack: Represent char range patterns with a typed-tree node #8893 adds an interval pattern node, and Support int range patterns #8894 accepts int ranges.New tests:
char_int_alias_test.res: conversions, mixed patterns,codePointAtresults, emoji (astral code points and surrogates), negative values.super_errors: warning 8 and warning 11 on mixed char/int patterns.CompletionChar.rescovers pipe completion on a char.🤖 Generated with Claude Code
https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo