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

Print :> without wrapping parenthesis #6254

Open
ryyppy opened this issue May 15, 2023 · 5 comments
Open

Print :> without wrapping parenthesis #6254

ryyppy opened this issue May 15, 2023 · 5 comments
Labels
Milestone

Comments

@ryyppy
Copy link
Member

ryyppy commented May 15, 2023

Given the following example:

type a = {"name": string, "age": int}

type b = {"name": string}

let v: a = {
  "name": "Anton",
  "age": 35,
}

let foo = (arg: b) => {
  Js.log("Hi" ++ arg["name"])
}

foo(v :> b)

Playground link

When pretty-printing the code, the coercion expression will be wrapped with parentheses: foo((v :> b)).

Expected behavior: It should print the expression the same way as it was defined; only preserve parentheses if the operation was originally wrapped in parentheses.

@cristianoc
Copy link
Collaborator

The parsing of coercion is spread out in several places. Not completely clear how to capture where parens are necessary or not.
Will need to either do on a case by case basis, or unify :> parsing with the behaviour of other binary operators.
Also, one needs to make sure that removing parens does not make the code more difficult to understand, even if it parses OK.

@cristianoc
Copy link
Collaborator

After a little investigation, its not clear which one is preferable in this specific example.
So I'll leave it here in case some new data / opinions emerge.

Copy link

github-actions bot commented Sep 7, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Old issues that went stale label Sep 7, 2024
@cknitt
Copy link
Member

cknitt commented Sep 7, 2024

#7024 just reminded me of this one. @shulhi do you think we should add this one to #6995 to investigate (even though it is not strictly speaking a bug)?

@github-actions github-actions bot removed the stale Old issues that went stale label Sep 8, 2024
@shulhi
Copy link
Member

shulhi commented Sep 8, 2024

#7024 just reminded me of this one. @shulhi do you think we should add this one to #6995 to investigate (even though it is not strictly speaking a bug)?

Sure thing, I added this to #6995

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

No branches or pull requests

4 participants