-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Print infix operations in infix form #22854
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
scala> scala.compiletime.codeOf(1+2) | ||
val res0: String = 1.+(2) | ||
val res0: String = 1 + 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dotty.tools.dotc.core | ||
|
||
import dotty.tools.dotc.core.NameOps.isOperatorName | ||
import dotty.tools.dotc.core.Names.{termName, SimpleName} | ||
|
||
import org.junit.Test | ||
|
||
class NameOpsTest: | ||
@Test def isOperatorNamePos: Unit = | ||
for name <- List("+", "::", "frozen_=:=", "$_+", "a2_+", "a_b_+") do | ||
assert(isOperatorName(termName(name))) | ||
|
||
@Test def isOperatorNameNeg: Unit = | ||
for name <- List("foo", "*_*", "<init>", "$reserved", "a*", "2*") do | ||
assert(!isOperatorName(termName(name))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[[syntax trees at end of typer]] // tests/printing/infix-operations.scala | ||
package <empty> { | ||
class C(a: Int) extends Object() { | ||
private[this] val a: Int | ||
def foo(b: Int): C = this | ||
def +(b: Int): C = this | ||
} | ||
final lazy module val infix-operations$package: infix-operations$package = | ||
new infix-operations$package() | ||
final module class infix-operations$package() extends Object() { | ||
this: infix-operations$package.type => | ||
@main def main: Unit = | ||
{ | ||
val v1: Int = 1 + 2 + 3 | ||
val v2: Int = 1 + (2 + 3) | ||
val v3: Int = 1 + 2 * 3 | ||
val v4: Int = (1 + 2) * 3 | ||
val v5: Int = (1 + 2):Int | ||
val v6: Int = (1 + 2):Int | ||
val v7: Boolean = (1 < 2):Boolean | ||
val v8: Boolean = (1 < 2):Boolean | ||
val c: C = new C(2) | ||
val v9: C = c.foo(3) | ||
val v10: C = c + 3 | ||
() | ||
} | ||
} | ||
final class main() extends Object() { | ||
<static> def main(args: Array[String]): Unit = | ||
try main catch | ||
{ | ||
case error @ _:scala.util.CommandLineParser.ParseError => | ||
scala.util.CommandLineParser.showError(error) | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class C(a: Int): | ||
def foo(b: Int): C = this | ||
def +(b: Int): C = this | ||
|
||
@main def main = | ||
val v1 = 1 + 2 + 3 | ||
val v2 = 1 + (2 + 3) | ||
val v3 = 1 + 2 * 3 | ||
val v4 = (1 + 2) * 3 | ||
val v5 = (1 + 2):Int | ||
val v6 = 1 + 2:Int // same as above | ||
val v7 = (1 < 2):Boolean | ||
val v8 = 1 < 2:Boolean // same as above | ||
|
||
val c = new C(2) // must not be printed in infix form | ||
val v9 = c.foo(3) // must not be printed in infix form | ||
val v10 = c + 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
1.+(2) | ||
1 + 2 | ||
{ | ||
scala.Predef.println(1) | ||
2 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@main def Test = assert(scala.compiletime.codeOf(1+2) == "1.+(2)") | ||
@main def Test = assert(scala.compiletime.codeOf(1+2) == "1 + 2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
List(Error(value check is not a member of Unit,compileError("1" * 2).check(""),22,Typer), Error(argument to compileError must be a statically known String but was: augmentString("1").*(2),compileError("1" * 2).check(""),13,Typer)) | ||
List(Error(value check is not a member of Unit,compileError("1" * 2).check(""),22,Typer), Error(argument to compileError must be a statically known String but was: augmentString("1") * 2,compileError("1" * 2).check(""),13,Typer)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andop
are defined in https://scala-lang.org/files/archive/spec/3.4/01-lexical-syntax.html.