Skip to content

GenType: distinguish inline records from unary variant cases of objec… #6586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

- experimental support of tagged template literals, eg ```sql`select * from ${table}```. https://github.com/rescript-lang/rescript-compiler/pull/6250

#### :bug: Bug Fix

- GenType: distinguish inline records from unary variant cases of object type. https://github.com/rescript-lang/rescript-compiler/pull/6586

# 11.0.1

#### :bug: Bug Fix
Expand Down
2 changes: 1 addition & 1 deletion jscomp/gentype/EmitType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
|> field ~name:(Runtime.jsVariantValue ~polymorphic);
]
|> fields
| false, Object (_, flds) ->
| false, Object (Inline, flds) ->
(* inlined record *)
tagField :: flds |> fields
| false, type_ ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/gentype/GenTypeCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let labelJSToString case =
| IntLabel i -> i
| StringLabel s -> s |> EmitText.quotes

type closedFlag = Open | Closed
type closedFlag = Open | Closed | Inline

type type_ =
| Array of type_ * mutable_
Expand Down
7 changes: 4 additions & 3 deletions jscomp/gentype/TranslateTypeDeclarations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
in
{CodeItem.importTypes; exportFromTypeDeclaration}
in
let translateLabelDeclarations ~recordRepresentation labelDeclarations =
let translateLabelDeclarations ?(inline = false) ~recordRepresentation
labelDeclarations =
let isOptional l =
match recordRepresentation with
| Types.Record_optional_labels lbls -> List.mem l lbls
Expand Down Expand Up @@ -131,7 +132,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
let type_ =
match fields with
| [field] when unboxedAnnotation -> field.type_
| _ -> Object (Closed, fields)
| _ -> Object ((if inline then Inline else Closed), fields)
in
{TranslateTypeExprFromTypes.dependencies; type_}
in
Expand Down Expand Up @@ -244,7 +245,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
| Cstr_record labelDeclarations ->
[
labelDeclarations
|> translateLabelDeclarations
|> translateLabelDeclarations ~inline:true
~recordRepresentation:Types.Record_regular;
]
in
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export type unboxedBinary = { TAG: "UB"; _0: typeD; _1: number };
export type inline =
{ TAG: "I"; readonly i: number; readonly j: number }
| { TAG: "J"; readonly i: number; readonly j: number }
| { TAG: "K"; _0: number; _1: number };
| { TAG: "K"; _0: number; _1: number }
| { TAG: "L"; _0: { readonly j: number; readonly i: number } };

export const makeVariant: () => typeL = NestedVariantsJS.makeVariant as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type inline =
| I({i: int, j: int})
| J({i: int, j: int})
| K(int, int)
| L({"i": int, "j": int})

@genType
let testBoxedBinary = (_: boxedBinary) => 34
Expand All @@ -74,5 +75,6 @@ let testInline = x =>
| I(q) => I({...q, i: q.i})
| J(q) => J(q)
| K(a, b) => K(b, a)
| L(q) => L(q)
}

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