Skip to content

Commit e5defc7

Browse files
committed
extract whether record field is optional from cmt
1 parent 54ebacd commit e5defc7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Diff for: analysis/src/ProcessCmt.ml

+18-3
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
8989
| Type_record (fields, _) ->
9090
Record
9191
(fields
92-
|> List.map (fun {Types.ld_id; ld_type} ->
92+
|> List.map (fun {Types.ld_id; ld_type; ld_attributes} ->
9393
let astamp = Ident.binding_time ld_id in
9494
let name = Ident.name ld_id in
9595
{
9696
stamp = astamp;
9797
fname = Location.mknoloc name;
9898
typ = ld_type;
99+
optional =
100+
Res_parsetree_viewer.hasOptionalAttribute
101+
ld_attributes;
99102
})));
100103
}
101104
~name ~stamp:(Ident.binding_time ident) ~env type_attributes
@@ -212,10 +215,22 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
212215
(fields
213216
|> List.map
214217
(fun
215-
{Typedtree.ld_id; ld_name = fname; ld_type = {ctyp_type}}
218+
{
219+
Typedtree.ld_id;
220+
ld_name = fname;
221+
ld_type = {ctyp_type};
222+
ld_attributes;
223+
}
216224
->
217225
let fstamp = Ident.binding_time ld_id in
218-
{stamp = fstamp; fname; typ = ctyp_type})));
226+
{
227+
stamp = fstamp;
228+
fname;
229+
typ = ctyp_type;
230+
optional =
231+
Res_parsetree_viewer.hasOptionalAttribute
232+
ld_attributes;
233+
})));
219234
}
220235
~name ~stamp ~env typ_attributes
221236
(Exported.add exported Exported.Type)

Diff for: analysis/src/SharedTypes.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ module ModulePath = struct
2424
loop modulePath [tipName]
2525
end
2626

27-
type field = {stamp: int; fname: string Location.loc; typ: Types.type_expr}
27+
type field = {
28+
stamp: int;
29+
fname: string Location.loc;
30+
typ: Types.type_expr;
31+
optional: bool;
32+
}
2833

2934
module Constructor = struct
3035
type t = {

0 commit comments

Comments
 (0)