Skip to content

Commit ef31be5

Browse files
authored
flambda-backend: pprintast recognize modalities on constructor arguments (#2329)
1 parent 54e3fe6 commit ef31be5

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

parsing/pprintast.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ and constructor_declaration ctxt f (name, vars_jkinds, args, res, attrs) =
19151915
(fun f -> function
19161916
| Pcstr_tuple [] -> ()
19171917
| Pcstr_tuple l ->
1918-
pp f "@;of@;%a" (list (core_type1 ctxt) ~sep:"@;*@;") l
1918+
pp f "@;of@;%a" (list (maybe_modes_type core_type1 ctxt) ~sep:"@;*@;") l
19191919
| Pcstr_record l -> pp f "@;of@;%a" (record_declaration ctxt) l
19201920
) args
19211921
(attributes ctxt) attrs
@@ -1925,7 +1925,7 @@ and constructor_declaration ctxt f (name, vars_jkinds, args, res, attrs) =
19251925
(fun f -> function
19261926
| Pcstr_tuple [] -> core_type1 ctxt f r
19271927
| Pcstr_tuple l -> pp f "%a@;->@;%a"
1928-
(list (core_type1 ctxt) ~sep:"@;*@;") l
1928+
(list (maybe_modes_type core_type1 ctxt) ~sep:"@;*@;") l
19291929
(core_type1 ctxt) r
19301930
| Pcstr_record l ->
19311931
pp f "%a@;->@;%a" (record_declaration ctxt) l (core_type1 ctxt) r

testsuite/tests/language-extensions/pprintast_unconditional.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ module Example = struct
1717
let parse p str = p (Lexing.from_string str)
1818
end
1919

20+
let modality_record = parse module_expr
21+
"struct \
22+
type t = {global_ x : string; global_ y : int} \
23+
end"
24+
let modality_cstrarg = parse module_expr
25+
"struct \
26+
type t = Foo of global_ string * global_ string \
27+
type u = Foo : global_ string * global_ string -> u \
28+
end"
29+
2030
let longident = parse longident "No.Longidents.Require.extensions"
2131
let expression = parse expression "[x for x = 1 to 10]"
2232
let pattern = parse pattern "[:_:]"
@@ -123,6 +133,9 @@ end = struct
123133
Test.setup ()
124134
;;
125135

136+
let modality_record = test "modality_record" module_expr Example.modality_record
137+
let modality_cstrarg = test "modality_cstrarg" module_expr Example.modality_cstrarg
138+
126139
let longident = test "longident" longident Example.longident
127140
let expression = test "expression" expression Example.expression
128141
let pattern = test "pattern" pattern Example.pattern

testsuite/tests/language-extensions/pprintast_unconditional.reference

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
##### All extensions enabled
22
--------------------------------
33

4+
modality_record: struct type t = {
5+
global_ x: string ;
6+
global_ y: int } end
7+
8+
modality_cstrarg:
9+
struct
10+
type t =
11+
| Foo of global_ string * global_ string
12+
type u =
13+
| Foo: global_ string * global_ string -> u
14+
end
15+
416
longident: No.Longidents.Require.extensions
517

618
expression: [x for x = 1 to 10]
@@ -58,6 +70,18 @@ tyvar: 'no_tyvars_require_extensions
5870
##### Extensions disallowed
5971
--------------------------------
6072

73+
modality_record: struct type t = {
74+
global_ x: string ;
75+
global_ y: int } end
76+
77+
modality_cstrarg:
78+
struct
79+
type t =
80+
| Foo of global_ string * global_ string
81+
type u =
82+
| Foo: global_ string * global_ string -> u
83+
end
84+
6185
longident: No.Longidents.Require.extensions
6286

6387
expression: [x for x = 1 to 10]

0 commit comments

Comments
 (0)