@@ -213,6 +213,7 @@ let transl_labels ?record_name env closed lbls =
213
213
{
214
214
pld_name = name ;
215
215
pld_mutable = mut ;
216
+ pld_optional = optional ;
216
217
pld_type = arg ;
217
218
pld_loc = loc ;
218
219
pld_attributes = attrs ;
@@ -224,6 +225,7 @@ let transl_labels ?record_name env closed lbls =
224
225
ld_id = Ident. create name.txt;
225
226
ld_name = name;
226
227
ld_mutable = mut;
228
+ ld_optional = optional;
227
229
ld_type = cty;
228
230
ld_loc = loc;
229
231
ld_attributes = attrs;
@@ -242,6 +244,7 @@ let transl_labels ?record_name env closed lbls =
242
244
{
243
245
Types. ld_id = ld.ld_id;
244
246
ld_mutable = ld.ld_mutable;
247
+ ld_optional = ld.ld_optional;
245
248
ld_type = ty;
246
249
ld_loc = ld.ld_loc;
247
250
ld_attributes = ld.ld_attributes;
@@ -365,9 +368,6 @@ let transl_declaration ~type_record_as_object env sdecl id =
365
368
| [] -> ()
366
369
| (_ , _ , loc ) :: _ ->
367
370
Location. prerr_warning loc Warnings. Constraint_on_gadt );
368
- let has_optional attrs =
369
- Ext_list. exists attrs (fun ({txt} , _ ) -> txt = " res.optional" )
370
- in
371
371
let scstrs =
372
372
Ext_list. map scstrs (fun ({pcd_args} as cstr ) ->
373
373
match pcd_args with
@@ -378,7 +378,7 @@ let transl_declaration ~type_record_as_object env sdecl id =
378
378
pcd_args =
379
379
Pcstr_record
380
380
(Ext_list. map lds (fun ld ->
381
- if has_optional ld.pld_attributes then
381
+ if ld.pld_optional then
382
382
let typ = ld.pld_type in
383
383
let typ =
384
384
{
@@ -475,6 +475,7 @@ let transl_declaration ~type_record_as_object env sdecl id =
475
475
ld_name =
476
476
Location. mkloc (Ident. name l.ld_id) l.ld_loc;
477
477
ld_mutable = l.ld_mutable;
478
+ ld_optional = l.ld_optional;
478
479
ld_type =
479
480
{
480
481
ctyp_desc = Ttyp_any ;
@@ -531,21 +532,17 @@ let transl_declaration ~type_record_as_object env sdecl id =
531
532
Ast_untagged_variants. check_well_formed ~env ~is_untagged_def cstrs;
532
533
(Ttype_variant tcstrs, Type_variant cstrs, sdecl)
533
534
| Ptype_record lbls_ -> (
534
- let has_optional attrs =
535
- Ext_list. exists attrs (fun ({txt} , _ ) -> txt = " res.optional" )
536
- in
537
535
let optional_labels =
538
536
Ext_list. filter_map lbls_ (fun lbl ->
539
- if has_optional lbl.pld_attributes then Some lbl.pld_name.txt
540
- else None )
537
+ if lbl.pld_optional then Some lbl.pld_name.txt else None )
541
538
in
542
539
let lbls =
543
540
if optional_labels = [] then lbls_
544
541
else
545
542
Ext_list. map lbls_ (fun lbl ->
546
543
let typ = lbl.pld_type in
547
544
let typ =
548
- if has_optional lbl.pld_attributes then
545
+ if lbl.pld_optional then
549
546
{
550
547
typ with
551
548
ptyp_desc =
@@ -575,6 +572,7 @@ let transl_declaration ~type_record_as_object env sdecl id =
575
572
ld_id = l.ld_id;
576
573
ld_name = {txt = Ident. name l.ld_id; loc = l.ld_loc};
577
574
ld_mutable = l.ld_mutable;
575
+ ld_optional = l.ld_optional;
578
576
ld_type =
579
577
{
580
578
ld_type with
@@ -634,8 +632,7 @@ let transl_declaration ~type_record_as_object env sdecl id =
634
632
check_duplicates sdecl.ptype_loc lbls StringSet. empty;
635
633
let optional_labels =
636
634
Ext_list. filter_map lbls (fun lbl ->
637
- if has_optional lbl.ld_attributes then Some lbl.ld_name.txt
638
- else None )
635
+ if lbl.ld_optional then Some lbl.ld_name.txt else None )
639
636
in
640
637
( Ttype_record lbls,
641
638
Type_record
0 commit comments