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

Skip trailing comma in explicit partial application #6949

Conversation

shulhi
Copy link
Member

@shulhi shulhi commented Aug 13, 2024

Fix #6948

@shulhi shulhi force-pushed the fix-trailing-comma-in-partial-function-dotdotdot branch from 9aa6b1a to b8428cf Compare August 13, 2024 08:11
@@ -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 *)
Copy link
Member Author

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.

@zth
Copy link
Collaborator

zth commented Aug 13, 2024

I think this looks good. @cristianoc any comments?

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you add a syntax test case too, so we see it being exercised.
(FTR, those would fail before your failed test, so you can test them locally on any machine)

@@ -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 =
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?
I kind of don't even remember using ... verbatim as label, instead of some other attribute.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I see in the parser let attrs = if is_partial then [res_partial_attr] else [] in
so I'm not sure your code runs? In any case, adding a test will answer this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label does not exist. In the ast.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Internally the distinction is only the presence of the attribute.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

@@ -4146,7 +4146,13 @@ and print_pexp_apply ~state expr cmt_tbl =
let partial, attrs = ParsetreeViewer.process_partial_app_attribute attrs in
let args =
if partial then
let dummy = Ast_helper.Exp.constant (Ast_helper.Const.int 0) in
let loc =
{Asttypes.txt = "res.partial"; Asttypes.loc = expr.pexp_loc}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the dummy attribute, I added res.partial so it can be pattern matched with the attribute rather than the label.

Copy link
Member Author

@shulhi shulhi Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at previous code, it doesn't look like the choice of the expression here matters. It only cares about the label, so tagging partial attribute here allows us to pattern match on the attribute rather than the label.

@shulhi shulhi marked this pull request as ready for review August 13, 2024 14:08
@cknitt
Copy link
Member

cknitt commented Aug 14, 2024

@shulhi Could you add a CHANGELOG entry?

@shulhi
Copy link
Member Author

shulhi commented Aug 14, 2024

@shulhi Could you add a CHANGELOG entry?

Done. Should we also backport this to v11?

@cknitt cknitt merged commit 9a65856 into rescript-lang:master Aug 15, 2024
20 checks passed
@cknitt
Copy link
Member

cknitt commented Aug 15, 2024

Done. Should we also backport this to v11?

Yes, I think so. I will do cherry picking to v11 in bulk at a later time.

@shulhi shulhi deleted the fix-trailing-comma-in-partial-function-dotdotdot branch August 15, 2024 10:37
cknitt pushed a commit to cknitt/rescript that referenced this pull request Sep 8, 2024
* Check for dotdotdot in args

* Check on attribute rather than label

* Add tests

* Fix naming convention

* Update CHANGELOG
cknitt pushed a commit to cknitt/rescript that referenced this pull request Sep 8, 2024
* Check for dotdotdot in args

* Check on attribute rather than label

* Add tests

* Fix naming convention

* Update CHANGELOG
cknitt pushed a commit that referenced this pull request Sep 10, 2024
* Check for dotdotdot in args

* Check on attribute rather than label

* Add tests

* Fix naming convention

* Update CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter Breaks Explicit Partial Application Syntax When Split By a Line Break
4 participants