Skip to content
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

Fix parentheses around optional module parameter #1212

Merged
merged 3 commits into from
Jan 21, 2020
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
+ Remove some calls to if_newline and break_unless_newline and fix break before closing brackets (#1168) (Guillaume Petiot)
+ Fix unstable cmt in or-pattern (#1173) (Guillaume Petiot)
+ Fix location of comment attached to the underscore of an open record (#1208) (Guillaume Petiot)
+ Fix parentheses around optional module parameter (#1212) (Christian Barcenas)

#### Documentation

Expand Down
7 changes: 6 additions & 1 deletion lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,15 @@ and fmt_fun_args c ?pro args =
( fmt_pattern c ~parens:false xpat
$ fmt " =@;<1 2>" $ fmt_expression c xexp ))
| Val (Optional l, xpat, Some xexp) ->
let parens =
match xpat.ast.ppat_desc with
| Ppat_unpack _ -> None
| _ -> Some false
in
cbox 2
( str "?" $ str l
$ wrap_k (fmt ":@,(") (str ")")
( fmt_pattern c ~parens:false xpat
( fmt_pattern c ?parens xpat
$ fmt " =@;<1 2>" $ fmt_expression c xexp ) )
| Val ((Labelled _ | Nolabel), _, Some _) ->
impossible "not accepted by parser"
Expand Down
5 changes: 5 additions & 0 deletions test/passing/module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ end
module A (_ : S) = struct end

module A : functor (_ : S) -> S' = functor (_ : S) -> struct end

let helper ?x =
match x with Some (module X : X_typ) -> X.f | None -> X_add_one.f

let helper ?x:((module X) = (module X_add_one : X_typ)) = X.f