File tree Expand file tree Collapse file tree 4 files changed +5
-6
lines changed
src-bootstrapped/scala/quoted Expand file tree Collapse file tree 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
66
77sealed abstract class Type [T <: AnyKind ] {
88 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 ]])
912}
1013
1114/** Some basic type tags, currently incomplete */
Original file line number Diff line number Diff line change @@ -1484,7 +1484,7 @@ trait Printers
14841484
14851485 case Type .SymRef (sym, prefix) if sym.isTerm =>
14861486 prefix match {
1487- case NoPrefix () =>
1487+ case NoPrefix () | Type . ThisType ( Types . EmptyPackage () | Types . RootPackage ()) =>
14881488 this += highlightTypeDef(sym.name, color)
14891489 case _ =>
14901490 printTypeOrBound(prefix)
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import scala.quoted._
22import scala .tasty ._
33
44object TypeToolbox {
5- inline def show [A ]: String = ~ showImpl(' [A ])
5+ inline def show [A ]: String = $ { showImpl(' [A ]) }
66 private def showImpl [A , B ](a : Type [A ])(implicit refl : Reflection ): Expr [String ] = {
77 import refl ._
88 import scala .quoted .Toolbox .Default ._
Original file line number Diff line number Diff line change @@ -3,10 +3,6 @@ object Test {
33 import TypeToolbox ._
44 def main (args : Array [String ]): Unit = {
55 val x = 5
6- println(show[Nil .type ])
7- println(show[Int => Int ])
8- println(show[(Int , String )])
9- println(show[x.type ])
106 assert(show[x.type ] == " x.type" )
117 assert(show[Nil .type ] == " scala.Nil.type" )
128 assert(show[Int ] == " scala.Int" )
You can’t perform that action at this time.
0 commit comments