File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+ import scala .tasty ._
3
+
4
+ object TypeToolbox {
5
+ inline def show [A ]: String = ~ showImpl(' [A ])
6
+ private def showImpl [A , B ](a : Type [A ])(implicit refl : Reflection ): Expr [String ] = {
7
+ import refl ._
8
+ import scala .quoted .Toolbox .Default ._
9
+ a.show.toExpr
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+
2
+ object Test {
3
+ import TypeToolbox ._
4
+ def main (args : Array [String ]): Unit = {
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
+ assert(show[x.type ] == " x.type" )
11
+ assert(show[Nil .type ] == " scala.Nil.type" )
12
+ assert(show[Int ] == " scala.Int" )
13
+ assert(show[Int => Int ] == " scala.Function1[scala.Int, scala.Int]" )
14
+ assert(show[(Int , String )] == " scala.Tuple2[scala.Int, scala.Predef.String]" )
15
+
16
+ // TODO: more complex types:
17
+ // - implicit function types
18
+ // - dependent function types
19
+ // - refinement types
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments