forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to get string representations for code passed in the interpolated values ```scala inline def logged(p1: => Any) = { val c = code"code: $p1" val res = p1 (c, p1) } logged(indentity("foo")) ``` is equivalent to: ```scala ("code: indentity("foo")", indentity("foo")) ```
- Loading branch information
Showing
12 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,9 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext("abc ", "", "").code(println(34))) // error | ||
} | ||
|
||
} |
This file contains 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,11 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def nonConstant: String = "" | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext("abc ", nonConstant).code(println(34))) // error | ||
} | ||
|
||
} |
This file contains 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,9 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext("abc ").code(println(34), 34)) // error | ||
} | ||
|
||
} |
This file contains 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,9 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext(Seq.empty[String]:_*).code(println(34))) // error | ||
} | ||
|
||
} |
This file contains 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,9 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext("abc").code(Seq.empty[Any]:_*)) // error | ||
} | ||
|
||
} |
This file contains 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,9 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(StringContext(Seq.empty[String]:_*).code(Seq.empty[Any]:_*)) // error | ||
} | ||
|
||
} |
This file contains 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,4 @@ | ||
-- Error: tests/neg/i6622f.scala:6:8 ----------------------------------------------------------------------------------- | ||
6 | fail(println("foo")) // error | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| failed: println("foo") ... |
This file contains 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,11 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
fail(println("foo")) // error | ||
} | ||
|
||
inline def fail(p1: => Any) = error(code"failed: $p1 ...") | ||
|
||
} |
This file contains 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 @@ | ||
import scala.compiletime._ | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
assert(code"abc ${println(34)} ..." == "abc println(34) ...") | ||
assert(code"abc ${println(34)}" == "abc println(34)") | ||
assert(code"${println(34)} ..." == "println(34) ...") | ||
assert(code"${println(34)}" == "println(34)") | ||
assert(code"..." == "...") | ||
assert(testConstant(code"") == "") | ||
} | ||
|
||
inline def testConstant(inline msg: String): String = msg | ||
} |