Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#### :bug: Bug fix

- Make rewatch compile independent modules after an unrelated failure and recompile blocked dependents when a changed interface survives a failed implementation, including across full watcher rebuilds. https://github.com/rescript-lang/rescript/pull/8667
- GenType: type inline-record cases of untagged variants as objects instead of their single field's type. https://github.com/rescript-lang/rescript/pull/8693
- Keep comments on labelled parameters with default values, and before `=?` in optional arrow-type arguments, when formatting. https://github.com/rescript-lang/rescript/pull/8690
- Fix invalid JavaScript that exported names left unbound when a module's toplevel always throws. https://github.com/rescript-lang/rescript/pull/8692
- Make module inclusion error messages independent of the length of the source file path. https://github.com/rescript-lang/rescript/pull/8691
Expand Down
5 changes: 1 addition & 4 deletions compiler/gentype/translate_type_declarations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
[
label_declarations
|> translate_label_declarations ~inline:true
~unboxed:
(type_representation = Unboxed
|| Variant_runtime.constructor_is_untagged layout
position);
~unboxed:(type_representation = Unboxed);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required changelog entry

This changes a user-visible generated TypeScript type and fixes incorrect genType output, but the commit does not update CHANGELOG.md; document the fix under the current Unreleased bug-fix section and include the required PR link.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 1abeeb3, under the Unreleased section with the PR link.

]
in
let arg_types =
Expand Down
6 changes: 0 additions & 6 deletions compiler/ml/variant_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,6 @@ let constructor_tag layout position =
| Constant tag -> tag.literal
| Block (Tagged {tag} | Untagged {tag}) -> tag.literal

let constructor_is_untagged layout position =
match constructor_at layout position with
| Constant _ -> false
| Block (Tagged _) -> false
| Block (Untagged _) -> true

let representation ({variant; position} : constructor_reference) =
constructor_at (get_layout variant) position

Expand Down
1 change: 0 additions & 1 deletion compiler/ml/variant_runtime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ val matching_facts : layout -> matching_facts
val configuration : layout -> configuration
val constructor_at : layout -> int -> constructor_case
val constructor_tag : layout -> int -> literal_tag option
val constructor_is_untagged : layout -> int -> bool
val representation : constructor_reference -> constructor_case
val length : layout -> int
val num_constants : layout -> int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ export type r1 = number;

export type r2 = string;

export type t = number[] | number | ((_1:number) => number);
export type t =
number[]
| { readonly x: number }
| ((_1:number) => number);

export type tabIndex = "0" | "1" | 0;

export const testV1: (x:v1) => v1 = UnboxedJS.testV1 as any;

export const r2Test: (x:r2) => r2 = UnboxedJS.r2Test as any;

export const tLength: (v:t) => number = UnboxedJS.tLength as any;

export const a: tabIndex = UnboxedJS.a as any;

export const b: tabIndex = UnboxedJS.b as any;
Expand Down
8 changes: 8 additions & 0 deletions tests/gentype_tests/typescript-react-example/src/Unboxed.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ type r2 = B({g: string})
@genType @unboxed
type t = Array(array<int>) | Record({x: int}) | Function(int => int)

@genType

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sign off the commit under DCO

The reviewed commit message has no Signed-Off-By: trailer, so it does not satisfy this repository's DCO commit requirement; add a valid sign-off before submitting the change.

AGENTS.md reference: AGENTS.md:L68-L72

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every commit on this branch carries a Signed-off-by trailer (git log --format='%(trailers:key=Signed-off-by)' origin/master..HEAD lists one per commit), so there is nothing to add.

let tLength = (v: t) =>
switch v {
| Array(a) => Array.length(a)
| Record({x}) => x
| Function(f) => f(0)
}

@genType
type tabIndex = | @as("0") Activity | @as("1") UserKeyword | @as(0) NumZero

Expand Down
13 changes: 13 additions & 0 deletions tests/gentype_tests/typescript-react-example/src/Unboxed.res.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/gentype_tests/typescript-react-example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as MyMath from "./MyMath.tsx";
import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen.tsx";
import * as Records from "./Records.gen.tsx";
import * as TestPromise from "./TestPromise.gen.tsx";
import * as Unboxed from "./Unboxed.gen.tsx";
import * as Variants from "./Variants.gen.tsx";
import {
printManyPayloads,
Expand Down Expand Up @@ -129,6 +130,8 @@ export const make: React.FC<Props> = (_x: Props) => {
return <div />;
};

consoleLog("Unboxed: tLength({ x: 3 }) =", Unboxed.tLength({ x: 3 }));

const signedMessage = DocStrings.signMessage("hello", 42);
consoleLog("signedMessage:", signedMessage);

Expand Down
6 changes: 5 additions & 1 deletion tests/tests/src/variantsMatching.gen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export type MyNullable_t<a> = null | undefined | a;

export type MyNullableExtended_t<a> = null | undefined | "WhyNotAnotherOne" | a;

export type UntaggedWithBool_t = string | number | boolean | string;
export type UntaggedWithBool_t =
string
| number
| boolean
| { readonly name: string };

export type UntaggedWithTuple_t = string | [number, number, string];
Loading