Skip to content

Commit 1ad7c7f

Browse files
smarterfmonniot
authored andcommitted
Fix pretty printer to handle using and erased modifier
1 parent 2d9eb1c commit 1ad7c7f

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala

+2-5
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,10 @@ object SourceCode {
809809
case Nil => Flags.EmptyFlags
810810
case arg :: _ => arg.symbol.flags
811811
}
812-
if (argFlags.is(Flags.Erased | Flags.Given)) {
813-
if (argFlags.is(Flags.Given)) this += " given"
814-
if (argFlags.is(Flags.Erased)) this += " erased"
815-
this += " "
816-
}
817812
inParens {
818813
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit "
814+
if (argFlags.is(Flags.Given)) this += "using "
815+
if (argFlags.is(Flags.Erased)) this += "erased "
819816

820817
def printSeparated(list: List[ValDef]): Unit = list match {
821818
case Nil =>

tests/run-macros/term-show.check

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@scala.annotation.internal.SourceFile("tests/run-macros/term-show/Test_2.scala") trait A() extends java.lang.Object {
2+
def imp(x: scala.Int)(implicit str: scala.Predef.String): scala.Int
3+
def use(`x₂`: scala.Int)(using `str₂`: scala.Predef.String): scala.Int
4+
def era(`x₃`: scala.Int)(erased `str₃`: scala.Predef.String): scala.Int
5+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted.*
2+
3+
object TypeToolbox {
4+
inline def show(inline className: String): String = ${ showImpl('className) }
5+
private def showImpl(className: Expr[String])(using Quotes) : Expr[String] =
6+
import quotes.reflect.*
7+
val Expr(name) = className: @unchecked
8+
val res = Symbol.requiredClass(name).tree.show
9+
println(res)
10+
Expr(res)
11+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.language.experimental.erasedDefinitions
2+
3+
trait A:
4+
def imp(x: Int)(implicit str: String): Int
5+
def use(x: Int)(using str: String): Int
6+
def era(x: Int)(erased str: String): Int
7+
8+
object Test {
9+
import TypeToolbox.*
10+
def main(args: Array[String]): Unit = {
11+
println(show("A"))
12+
}
13+
}

0 commit comments

Comments
 (0)