@@ -1440,15 +1440,40 @@ let transl_with_constraint env id row_path orig_decl sdecl =
14401440 | Some ty -> raise(Error (sdecl.ptype_loc, Unbound_type_var (ty,decl)))
14411441 end ;
14421442 let decl = name_recursion sdecl id decl in
1443- let type_variance =
1443+ let new_type_variance =
14441444 try Typedecl_variance. compute_decl
14451445 env ~check: true decl (Typedecl_variance. variance_of_sdecl sdecl)
14461446 with Typedecl_variance. Error (loc , err ) ->
14471447 raise (Error (loc, Variance err)) in
1448- let type_immediate =
1448+ let new_type_immediate =
14491449 (* Typedecl_immediacy.compute_decl never raises *)
14501450 Typedecl_immediacy. compute_decl env decl in
1451- let decl = {decl with type_variance; type_immediate} in
1451+ let new_type_separability =
1452+ try Typedecl_separability. compute_decl env decl
1453+ with Typedecl_separability. Error (loc , err ) ->
1454+ raise (Error (loc, Separability err)) in
1455+ let decl =
1456+ (* we intentionally write this without a fragile { decl with ... }
1457+ to ensure that people adding new fields to type declarations
1458+ consider whether they need to recompute it here; for an example
1459+ of bug caused by the previous approach, see #9607 *)
1460+ {
1461+ type_params = decl.type_params;
1462+ type_arity = decl.type_arity;
1463+ type_kind = decl.type_kind;
1464+ type_private = decl.type_private;
1465+ type_manifest = decl.type_manifest;
1466+ type_unboxed = decl.type_unboxed;
1467+ type_is_newtype = decl.type_is_newtype;
1468+ type_expansion_scope = decl.type_expansion_scope;
1469+ type_loc = decl.type_loc;
1470+ type_attributes = decl.type_attributes;
1471+ type_uid = decl.type_uid;
1472+
1473+ type_variance = new_type_variance;
1474+ type_immediate = new_type_immediate;
1475+ type_separability = new_type_separability;
1476+ } in
14521477 Ctype. end_def() ;
14531478 generalize_decl decl;
14541479 {
0 commit comments