-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
c216dd2
to
2feab11
Compare
val v2: Int = 1 + (2 + 3) | ||
val v3: Int = 1 + 2 * 3 | ||
val v4: Int = (1 + 2) * 3 | ||
val v5: Int = 1 + 2:Int |
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.
aren't the parentheses important to preserve here? (1 + 2):Int
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.
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.
This comment has been minimized.
This comment has been minimized.
a5ea8a1
to
7d97b83
Compare
7d97b83
to
66094a1
Compare
As you already had a look (thanks!), would you be available to review this PR @bishabosha? :) |
def isOperatorName: Boolean = name match | ||
case name: SimpleName => name.exists(isOperatorPart) | ||
case _ => false | ||
/** Does this name match `[{letter | digit} '_'] op`? |
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.
Note: letter
, digit
and op
are defined in https://scala-lang.org/files/archive/spec/3.4/01-lexical-syntax.html.
No description provided.