Skip to content

Commit f62f83c

Browse files
cknittclaude
andauthored
Translate char to number in genType (#8988)
Why: `char` is an alias of `int` since #8892, but genType's table of builtin types had no row for it and does not expand the abbreviation, so a `char` in a genType signature was emitted as the TypeScript type `char`, which does not exist. Representation modified (genType's TypeScript type of char): Example: @Gentype let char0 = (x: char) => x Before (text): export const char0: (x:char) => char = CoreJS.char0 as any; After (text): export const char0: (x:number) => number = CoreJS.char0 as any; Claude-Session: https://claude.ai/code/session_01Xk6AeCYpCK4SZRtHYKHGoe Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9ad2cfb commit f62f83c

5 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎changes/gentype-char-number.fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- genType emits `char` as the TypeScript type `number` instead of `char`, which TypeScript does not know.

‎compiler/gentype/translate_type_expr_from_types.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
6767
in
6868
match (path |> path_to_list |> List.rev, params_translation) with
6969
| ["bool"], [] -> {dependencies = []; type_ = boolean_t}
70-
| ["int"], [] -> {dependencies = []; type_ = number_t}
70+
| (["int"] | ["char"]), [] -> {dependencies = []; type_ = number_t}
7171
| ["float"], [] -> {dependencies = []; type_ = number_t}
7272
| (["string"] | ["Stdlib"; "String"; "t"]), [] ->
7373
{dependencies = []; type_ = string_t}

‎tests/gentype_tests/typescript-react-example/src/Core.gen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const taggedTemplate1: (x:((strings:TemplateStringsArray, ...values:strin
5151

5252
export const date1: (x:Date) => Date = CoreJS.date1 as any;
5353

54+
export const char0: (x:number) => number = CoreJS.char0 as any;
55+
5456
export const bigint0: (x:bigint) => bigint = CoreJS.bigint0 as any;
5557

5658
export const stdlibBigInt: (x:bigint) => bigint = CoreJS.stdlibBigInt as any;

‎tests/gentype_tests/typescript-react-example/src/Core.res‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ let taggedTemplate1 = (x: TaggedTemplate.t<string, string>) => x
3434
@genType
3535
let date1 = (x: Date.t) => x
3636

37+
@genType
38+
let char0 = (x: char) => x
39+
3740
@genType
3841
let bigint0 = (x: bigint) => x
3942

‎tests/gentype_tests/typescript-react-example/src/Core.res.js‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)