Skip to content

Commit 6a58feb

Browse files
authored
Support {} for empty inlined record literals and types (#5900)
* add test * fix type error of empty inlined record * update CHANGELOG.md
1 parent c91c898 commit 6a58feb

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ These are only breaking changes for unformatted code.
6161

6262
# 10.1.1
6363

64+
#### :rocket: New Feature
65+
66+
- Add support for empty inlined record literal `{}` for inlined records where all fields are optional https://github.com/rescript-lang/rescript-compiler/pull/5900
67+
6468
#### :bug: Bug Fix
6569

6670
- Prevent inlining of async functions in additional cases https://github.com/rescript-lang/rescript-compiler/issues/5860

jscomp/ml/typecore.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21692169
| [], Some (representation) when lid_sexp_list = [] ->
21702170
let optional_labels = match representation with
21712171
| Record_optional_labels optional_labels -> optional_labels
2172+
| Record_inlined {optional_labels} -> optional_labels
21722173
| _ -> [] in
21732174
let filter_missing (ld : Types.label_declaration) =
21742175
let name = Ident.name ld.ld_id in

jscomp/test/record_regression.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ var h = newrecord$2;
257257

258258
var h10 = newrecord$3;
259259

260+
var ir4 = /* V0 */{
261+
x: 3
262+
};
263+
264+
var ir5 = /* V0 */{};
265+
260266
exports.f1 = f1;
261267
exports.f2 = f2;
262268
exports.f3 = f3;
@@ -280,4 +286,6 @@ exports.pm2 = pm2;
280286
exports.inlinedRecord = inlinedRecord;
281287
exports.pm3 = pm3;
282288
exports.pm4 = pm4;
289+
exports.ir4 = ir4;
290+
exports.ir5 = ir5;
283291
/* Not a pure module */

jscomp/test/record_regression.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ let inlinedRecord = ir =>
123123
}
124124
let pm3 = inlinedRecord(ir2)
125125
let pm4 = inlinedRecord(ir3)
126+
127+
type inlinedOptional2 = V0({x?: int})
128+
let ir4 = V0({x: 3})
129+
let ir5 = V0({})

0 commit comments

Comments
 (0)