Skip to content

Commit 115ec19

Browse files
author
Nathan Rebours
committed
Check attached attributes in decode function rather than migration
Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
1 parent 4a560fe commit 115ec19

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

astlib/encoding_504.ml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,31 +434,33 @@ module To_503 = struct
434434
let encode_bivariant_psig_class_type ~loc ctds =
435435
encode_bivariant_psig ~loc (Psig_class_type ctds)
436436

437-
let decode_bivariant_pstr ~loc payload =
438-
match payload with
439-
| PStr
440-
[
441-
{
442-
pstr_desc =
443-
(Pstr_type _ | Pstr_typext _ | Pstr_class _ | Pstr_class_type _)
444-
as x;
445-
_;
446-
};
447-
] ->
437+
let decode_bivariant_pstr ~loc payload attributes =
438+
match (payload, attributes) with
439+
| ( PStr
440+
[
441+
{
442+
pstr_desc =
443+
(Pstr_type _ | Pstr_typext _ | Pstr_class _ | Pstr_class_type _)
444+
as x;
445+
_;
446+
};
447+
],
448+
[] ) ->
448449
x
449450
| _ -> invalid_encoding ~loc "bivariant structure_item"
450451

451-
let decode_bivariant_psig ~loc payload =
452-
match payload with
453-
| PSig
454-
[
455-
{
456-
psig_desc =
457-
( Psig_type _ | Psig_typesubst _ | Psig_typext _ | Psig_class _
458-
| Psig_class_type _ ) as x;
459-
_;
460-
};
461-
] ->
452+
let decode_bivariant_psig ~loc payload attributes =
453+
match (payload, attributes) with
454+
| ( PSig
455+
[
456+
{
457+
psig_desc =
458+
( Psig_type _ | Psig_typesubst _ | Psig_typext _ | Psig_class _
459+
| Psig_class_type _ ) as x;
460+
_;
461+
};
462+
],
463+
[] ) ->
462464
x
463465
| _ -> invalid_encoding ~loc "bivariant signature_item"
464466

astlib/encoding_504.mli

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ module To_503 : sig
6868
val encode_bivariant_pmty_with :
6969
loc:Location.t -> module_type -> with_constraint list -> module_type_desc
7070

71-
val decode_bivariant_pstr : loc:Location.t -> payload -> structure_item_desc
72-
val decode_bivariant_psig : loc:Location.t -> payload -> signature_item_desc
71+
val decode_bivariant_pstr :
72+
loc:Location.t -> payload -> attributes -> structure_item_desc
73+
74+
val decode_bivariant_psig :
75+
loc:Location.t -> payload -> attributes -> signature_item_desc
76+
7377
val decode_bivariant_pmty_with : loc:Location.t -> payload -> module_type_desc
7478
end
7579

astlib/migrate_503_504.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,9 @@ and copy_structure_item_desc_with_loc ~loc :
585585
Ast_504.Parsetree.Pstr_include (copy_include_declaration x0)
586586
| Ast_503.Parsetree.Pstr_attribute x0 ->
587587
Ast_504.Parsetree.Pstr_attribute (copy_attribute x0)
588-
| Ast_503.Parsetree.Pstr_extension (({ txt; _ }, payload), [])
588+
| Ast_503.Parsetree.Pstr_extension (({ txt; _ }, payload), attr)
589589
when String.equal txt Encoding_504.Ext_name.bivariant_pstr ->
590-
let desc = Encoding_504.To_503.decode_bivariant_pstr ~loc payload in
590+
let desc = Encoding_504.To_503.decode_bivariant_pstr ~loc payload attr in
591591
copy_structure_item_desc_with_loc ~loc desc
592592
| Ast_503.Parsetree.Pstr_extension (x0, x1) ->
593593
Ast_504.Parsetree.Pstr_extension (copy_extension x0, copy_attributes x1)
@@ -884,9 +884,9 @@ and copy_signature_item_desc_with_loc ~loc :
884884
(List.map copy_class_type_declaration x0)
885885
| Ast_503.Parsetree.Psig_attribute x0 ->
886886
Ast_504.Parsetree.Psig_attribute (copy_attribute x0)
887-
| Ast_503.Parsetree.Psig_extension (({ txt; _ }, payload), [])
887+
| Ast_503.Parsetree.Psig_extension (({ txt; _ }, payload), attr)
888888
when String.equal txt Encoding_504.Ext_name.bivariant_psig ->
889-
let desc = Encoding_504.To_503.decode_bivariant_psig ~loc payload in
889+
let desc = Encoding_504.To_503.decode_bivariant_psig ~loc payload attr in
890890
copy_signature_item_desc_with_loc ~loc desc
891891
| Ast_503.Parsetree.Psig_extension (x0, x1) ->
892892
Ast_504.Parsetree.Psig_extension (copy_extension x0, copy_attributes x1)

0 commit comments

Comments
 (0)