Skip to content

Commit 2bff632

Browse files
committed
Fix issue with inlining records in the presence of record coercion
Fixes #6253
1 parent 8a5de48 commit 2bff632

6 files changed

+60
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#### :nail_care: Polish
1919
- Removed duplicate Super_error implementation in syntax https://github.com/rescript-lang/rescript-compiler/pull/6246
2020

21+
#### :bug: Bug Fix
22+
- Fix issue with inlining records in the presence of record coercion https://github.com/rescript-lang/rescript-compiler/pull/6256
23+
2124
# 11.0.0-alpha.6
2225

2326
#### :boom: Breaking Change

jscomp/core/lam_util.ml

+12-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,18 @@ let field_flatten_get
193193
| SimpleForm l -> l
194194
| exception _ -> lam ()
195195
end
196-
| Some (Constant (Const_block (_,_,ls))) ->
196+
| Some (Constant (Const_block (_, Blk_record {fields}, ls))) ->
197+
(match info with
198+
| Fld_record {name} ->
199+
let found = ref None in
200+
for i = 1 to Array.length fields - 1 do
201+
if fields.(i) = name then found := Ext_list.nth_opt ls i done;
202+
(match !found with
203+
| Some c -> Lam.const c
204+
| None -> lam())
205+
| _ -> lam ()
206+
)
207+
| Some (Constant (Const_block (_,_,ls))) ->
197208
begin match Ext_list.nth_opt ls i with
198209
| None -> lam ()
199210
| Some x -> Lam.const x

jscomp/test/RecordCoercion.js

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/RecordCoercion.res

+16
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ let _ = (x: r3) => (x :> r4) // omit everything
1515
type nested1 = {n: r1, extra: int}
1616
type nested2 = {n: r2}
1717
let _ = (x: nested1) => (x :> nested2)
18+
19+
module TestInlining = {
20+
type a = {
21+
number: int,
22+
name: string,
23+
}
24+
25+
type b = {name: string}
26+
27+
let a: a = {
28+
number: 42,
29+
name: "a",
30+
}
31+
32+
let name = (a :> b).name
33+
}

jscomp/test/record_with_test.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/update_record_test.js

+11-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)