diff --git a/CHANGELOG.md b/CHANGELOG.md index 463ee16fa6..75a48f414c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ #### :nail_care: Polish - Removed duplicate Super_error implementation in syntax https://github.com/rescript-lang/rescript-compiler/pull/6246 +#### :bug: Bug Fix +- Fix issue with inlining records in the presence of record coercion https://github.com/rescript-lang/rescript-compiler/pull/6256 + # 11.0.0-alpha.6 #### :boom: Breaking Change diff --git a/jscomp/core/lam_util.ml b/jscomp/core/lam_util.ml index 2e1589989d..36fc31bc1a 100644 --- a/jscomp/core/lam_util.ml +++ b/jscomp/core/lam_util.ml @@ -193,7 +193,18 @@ let field_flatten_get | SimpleForm l -> l | exception _ -> lam () end - | Some (Constant (Const_block (_,_,ls))) -> + | Some (Constant (Const_block (_, Blk_record {fields}, ls))) -> + (match info with + | Fld_record {name} -> + let found = ref None in + for i = 0 to Array.length fields - 1 do + if fields.(i) = name then found := Ext_list.nth_opt ls i done; + (match !found with + | Some c -> Lam.const c + | None -> lam()) + | _ -> lam () + ) + | Some (Constant (Const_block (_,_,ls))) -> begin match Ext_list.nth_opt ls i with | None -> lam () | Some x -> Lam.const x diff --git a/jscomp/test/RecordCoercion.js b/jscomp/test/RecordCoercion.js index d856702bfe..ea6d174265 100644 --- a/jscomp/test/RecordCoercion.js +++ b/jscomp/test/RecordCoercion.js @@ -1,2 +1,16 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ +'use strict'; + + +var TestInlining_a = { + number: 42, + name: "a" +}; + +var TestInlining = { + a: TestInlining_a, + name: "a" +}; + +exports.TestInlining = TestInlining; +/* No side effect */ diff --git a/jscomp/test/RecordCoercion.res b/jscomp/test/RecordCoercion.res index f577989ed7..c57cc11a6d 100644 --- a/jscomp/test/RecordCoercion.res +++ b/jscomp/test/RecordCoercion.res @@ -15,3 +15,19 @@ let _ = (x: r3) => (x :> r4) // omit everything type nested1 = {n: r1, extra: int} type nested2 = {n: r2} let _ = (x: nested1) => (x :> nested2) + +module TestInlining = { + type a = { + number: int, + name: string, + } + + type b = {name: string} + + let a: a = { + number: 42, + name: "a", + } + + let name = (a :> b).name +}