Skip to content

Print :> without wrapping parenthesis #6254

Closed

Description

@ryyppy

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.

Activity

  1. added this to the v12 milestone on May 15, 2023
  2. cristianoc commented on May 17, 2023

    @cristianoc
    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.

  3. cristianoc commented on May 17, 2023

    @cristianoc
    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.

  4. github-actions commented on Sep 7, 2024

    @github-actions

    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.

  5. added
    stale
    on Sep 7, 2024
  6. cknitt commented on Sep 7, 2024

    @cknitt
    Member

    #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)?

  7. removed
    stale
    on Sep 8, 2024
  8. shulhi commented on Sep 8, 2024

    @shulhi
    Member

    #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

  9. modified the milestones: v12, v12.1 on May 5, 2025
  10. added
    formatter
    and removed on Dec 3, 2025
  11. modified the milestones: v12.1, v13 on Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatter

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions