Skip to content

Commit 28b3b9a

Browse files
committed
GenType: distinguish inline records from unary variant cases of object type.
Fixes #6584
1 parent 6fa3289 commit 28b3b9a

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

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

19+
#### :bug: Bug Fix
20+
21+
- GenType: distinguish inline records from unary variant cases of object type. https://github.com/rescript-lang/rescript-compiler/pull/6586
22+
1923
# 11.0.1
2024

2125
#### :bug: Bug Fix

jscomp/gentype/EmitType.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
203203
|> field ~name:(Runtime.jsVariantValue ~polymorphic);
204204
]
205205
|> fields
206-
| false, Object (_, flds) ->
206+
| false, Object (Inline, flds) ->
207207
(* inlined record *)
208208
tagField :: flds |> fields
209209
| false, type_ ->

jscomp/gentype/GenTypeCommon.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let labelJSToString case =
6262
| IntLabel i -> i
6363
| StringLabel s -> s |> EmitText.quotes
6464

65-
type closedFlag = Open | Closed
65+
type closedFlag = Open | Closed | Inline
6666

6767
type type_ =
6868
| Array of type_ * mutable_

jscomp/gentype/TranslateTypeDeclarations.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
8585
in
8686
{CodeItem.importTypes; exportFromTypeDeclaration}
8787
in
88-
let translateLabelDeclarations ~recordRepresentation labelDeclarations =
88+
let translateLabelDeclarations ?(inline = false) ~recordRepresentation
89+
labelDeclarations =
8990
let isOptional l =
9091
match recordRepresentation with
9192
| Types.Record_optional_labels lbls -> List.mem l lbls
@@ -131,7 +132,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
131132
let type_ =
132133
match fields with
133134
| [field] when unboxedAnnotation -> field.type_
134-
| _ -> Object (Closed, fields)
135+
| _ -> Object ((if inline then Inline else Closed), fields)
135136
in
136137
{TranslateTypeExprFromTypes.dependencies; type_}
137138
in
@@ -244,7 +245,7 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
244245
| Cstr_record labelDeclarations ->
245246
[
246247
labelDeclarations
247-
|> translateLabelDeclarations
248+
|> translateLabelDeclarations ~inline:true
248249
~recordRepresentation:Types.Record_regular;
249250
]
250251
in

jscomp/gentype_tests/typescript-react-example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/NestedVariants.gen.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export type unboxedBinary = { TAG: "UB"; _0: typeD; _1: number };
4141
export type inline =
4242
{ TAG: "I"; readonly i: number; readonly j: number }
4343
| { TAG: "J"; readonly i: number; readonly j: number }
44-
| { TAG: "K"; _0: number; _1: number };
44+
| { TAG: "K"; _0: number; _1: number }
45+
| { TAG: "L"; _0: { readonly j: number; readonly i: number } };
4546

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

jscomp/gentype_tests/typescript-react-example/src/NestedVariants.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type inline =
6161
| I({i: int, j: int})
6262
| J({i: int, j: int})
6363
| K(int, int)
64+
| L({"i": int, "j": int})
6465

6566
@genType
6667
let testBoxedBinary = (_: boxedBinary) => 34
@@ -74,5 +75,6 @@ let testInline = x =>
7475
| I(q) => I({...q, i: q.i})
7576
| J(q) => J(q)
7677
| K(a, b) => K(b, a)
78+
| L(q) => L(q)
7779
}
7880

jscomp/gentype_tests/typescript-react-example/src/NestedVariants.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)