-
Notifications
You must be signed in to change notification settings - Fork 463
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
Skip trailing comma in explicit partial application #6949
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4730,6 +4730,20 @@ and print_arguments ~state ?(partial = false) | |
in | ||
Doc.concat [Doc.lparen; arg_doc; Doc.rparen] | ||
| args -> | ||
(* Avoid printing trailing comma when there is ... in function application *) | ||
let hasDotDotDot, printed_args = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would you do a little search if this functionality already exists somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I see in the parser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder which is better, pattern match on the label or the expression like so, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The label does not exist. In the ast. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think of it as app1(f, args) vs app2(f, args) One being total and the other partial. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So "..." only exists as string in the source, but that's not how it's represented in the AST. |
||
List.fold_right | ||
(fun arg (flag, acc) -> | ||
let arg_lbl, _ = arg in | ||
let hasDotDotDot = | ||
match arg_lbl with | ||
| Asttypes.Labelled "..." -> true | ||
| _ -> false | ||
in | ||
let doc = print_argument ~state arg cmt_tbl in | ||
(flag || hasDotDotDot, doc :: acc)) | ||
args (false, []) | ||
in | ||
Doc.group | ||
(Doc.concat | ||
[ | ||
|
@@ -4738,13 +4752,9 @@ and print_arguments ~state ?(partial = false) | |
(Doc.concat | ||
[ | ||
Doc.soft_line; | ||
Doc.join | ||
~sep:(Doc.concat [Doc.comma; Doc.line]) | ||
(List.map | ||
(fun arg -> print_argument ~state arg cmt_tbl) | ||
args); | ||
Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printed_args; | ||
]); | ||
(if partial then Doc.nil else Doc.trailing_comma); | ||
(if partial || hasDotDotDot then Doc.nil else Doc.trailing_comma); | ||
Doc.soft_line; | ||
Doc.rparen; | ||
]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters whether to check if
...
happens at the end because that's already considered as syntax error.