File tree 4 files changed +5
-6
lines changed
src-bootstrapped/scala/quoted
4 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ import scala.runtime.quoted.Unpickler.Pickled
6
6
7
7
sealed abstract class Type [T <: AnyKind ] {
8
8
type `$splice` = T
9
+
10
+ /** Show a source code like representation of this type */
11
+ final def show (implicit toolbox : Toolbox ): String = toolbox.show(this .asInstanceOf [Type [Any ]])
9
12
}
10
13
11
14
/** Some basic type tags, currently incomplete */
Original file line number Diff line number Diff line change @@ -1484,7 +1484,7 @@ trait Printers
1484
1484
1485
1485
case Type .SymRef (sym, prefix) if sym.isTerm =>
1486
1486
prefix match {
1487
- case NoPrefix () =>
1487
+ case NoPrefix () | Type . ThisType ( Types . EmptyPackage () | Types . RootPackage ()) =>
1488
1488
this += highlightTypeDef(sym.name, color)
1489
1489
case _ =>
1490
1490
printTypeOrBound(prefix)
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import scala.quoted._
2
2
import scala .tasty ._
3
3
4
4
object TypeToolbox {
5
- inline def show [A ]: String = ~ showImpl(' [A ])
5
+ inline def show [A ]: String = $ { showImpl(' [A ]) }
6
6
private def showImpl [A , B ](a : Type [A ])(implicit refl : Reflection ): Expr [String ] = {
7
7
import refl ._
8
8
import scala .quoted .Toolbox .Default ._
Original file line number Diff line number Diff line change @@ -3,10 +3,6 @@ object Test {
3
3
import TypeToolbox ._
4
4
def main (args : Array [String ]): Unit = {
5
5
val x = 5
6
- println(show[Nil .type ])
7
- println(show[Int => Int ])
8
- println(show[(Int , String )])
9
- println(show[x.type ])
10
6
assert(show[x.type ] == " x.type" )
11
7
assert(show[Nil .type ] == " scala.Nil.type" )
12
8
assert(show[Int ] == " scala.Int" )
You can’t perform that action at this time.
0 commit comments