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 infix operations in infix form #22854

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Mar 21, 2025

No description provided.

@mbovel mbovel force-pushed the mb/print-infix-ops branch from c216dd2 to 2feab11 Compare March 21, 2025 17:16
val v2: Int = 1 + (2 + 3)
val v3: Int = 1 + 2 * 3
val v4: Int = (1 + 2) * 3
val v5: Int = 1 + 2:Int
Copy link
Member

@bishabosha bishabosha Mar 22, 2025

Choose a reason for hiding this comment

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

aren't the parentheses important to preserve here? (1 + 2):Int

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because + has a higher precedence than :, so 1 + 2 : Int is the same as (1 + 2) : Int:

ValDef(v5, TypeTree(),
  Typed(Apply(Select(Literal(1), +), List(Literal(2))), Ident(Int))),
ValDef(v6, TypeTree(),
  Typed(Apply(Select(Literal(1), +), List(Literal(2))), Ident(Int)))

However it definitely seems confusing to me as well, so maybe we could print Typed with a higher precedence even if it's not required for correctness. I pushed a commit that does that.

@mbovel

This comment has been minimized.

@mbovel mbovel force-pushed the mb/print-infix-ops branch from a5ea8a1 to 7d97b83 Compare March 24, 2025 12:52
@mbovel mbovel force-pushed the mb/print-infix-ops branch from 7d97b83 to 66094a1 Compare March 24, 2025 12:53
@mbovel
Copy link
Member Author

mbovel commented Mar 24, 2025

As you already had a look (thanks!), would you be available to review this PR @bishabosha? :)

@mbovel mbovel requested a review from bishabosha March 24, 2025 13:06
def isOperatorName: Boolean = name match
case name: SimpleName => name.exists(isOperatorPart)
case _ => false
/** Does this name match `[{letter | digit} '_'] op`?
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

2 participants