Skip to content

pprintast recognize modalities on constructor arguments #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ocaml/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
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