Skip to content

Commit

Permalink
flambda-backend: pprintast recognize modalities on constructor argu…
Browse files Browse the repository at this point in the history
…ments (#2329)
  • Loading branch information
riaqn authored Mar 2, 2024
1 parent 54e3fe6 commit ef31be5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ and constructor_declaration ctxt f (name, vars_jkinds, args, res, attrs) =
(fun f -> function
| Pcstr_tuple [] -> ()
| Pcstr_tuple l ->
pp f "@;of@;%a" (list (core_type1 ctxt) ~sep:"@;*@;") l
pp f "@;of@;%a" (list (maybe_modes_type core_type1 ctxt) ~sep:"@;*@;") l
| Pcstr_record l -> pp f "@;of@;%a" (record_declaration ctxt) l
) args
(attributes ctxt) attrs
Expand All @@ -1925,7 +1925,7 @@ and constructor_declaration ctxt f (name, vars_jkinds, args, res, attrs) =
(fun f -> function
| Pcstr_tuple [] -> core_type1 ctxt f r
| Pcstr_tuple l -> pp f "%a@;->@;%a"
(list (core_type1 ctxt) ~sep:"@;*@;") l
(list (maybe_modes_type core_type1 ctxt) ~sep:"@;*@;") l
(core_type1 ctxt) r
| Pcstr_record l ->
pp f "%a@;->@;%a" (record_declaration ctxt) l (core_type1 ctxt) r
Expand Down
13 changes: 13 additions & 0 deletions testsuite/tests/language-extensions/pprintast_unconditional.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ module Example = struct
let parse p str = p (Lexing.from_string str)
end

let modality_record = parse module_expr
"struct \
type t = {global_ x : string; global_ y : int} \
end"
let modality_cstrarg = parse module_expr
"struct \
type t = Foo of global_ string * global_ string \
type u = Foo : global_ string * global_ string -> u \
end"

let longident = parse longident "No.Longidents.Require.extensions"
let expression = parse expression "[x for x = 1 to 10]"
let pattern = parse pattern "[:_:]"
Expand Down Expand Up @@ -123,6 +133,9 @@ end = struct
Test.setup ()
;;

let modality_record = test "modality_record" module_expr Example.modality_record
let modality_cstrarg = test "modality_cstrarg" module_expr Example.modality_cstrarg

let longident = test "longident" longident Example.longident
let expression = test "expression" expression Example.expression
let pattern = test "pattern" pattern Example.pattern
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
##### All extensions enabled
--------------------------------

modality_record: struct type t = {
global_ x: string ;
global_ y: int } end

modality_cstrarg:
struct
type t =
| Foo of global_ string * global_ string
type u =
| Foo: global_ string * global_ string -> u
end

longident: No.Longidents.Require.extensions

expression: [x for x = 1 to 10]
Expand Down Expand Up @@ -58,6 +70,18 @@ tyvar: 'no_tyvars_require_extensions
##### Extensions disallowed
--------------------------------

modality_record: struct type t = {
global_ x: string ;
global_ y: int } end

modality_cstrarg:
struct
type t =
| Foo of global_ string * global_ string
type u =
| Foo: global_ string * global_ string -> u
end

longident: No.Longidents.Require.extensions

expression: [x for x = 1 to 10]
Expand Down

0 comments on commit ef31be5

Please sign in to comment.