File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ (Test_2$package.Id,Test_2$package.Id,scala.Long)
2
+ (task.Title,task.Title,task.Title)
3
+ Task.run
4
+ (Test_2$package.Id,Test_2$package.Id,Test_2$package.Id)
5
+ (Task.this.Title,Task.this.Title,java.lang.String)
Original file line number Diff line number Diff line change
1
+ import scala .quoted .*
2
+
3
+ object Macro :
4
+ transparent inline def getType [T ] =
5
+ $ { getTypeImpl[T ] }
6
+ private def getTypeImpl [T : Type ](using Quotes ): Expr [Any ] =
7
+ import quotes .reflect .*
8
+
9
+ val tpe = TypeRepr .of[T ]
10
+ val reprShow = tpe.show
11
+ tpe.asType match
12
+ case ' [t] =>
13
+ val typeShow = TypeRepr .of[t].show // dealiased type
14
+ Expr ((Type .show[T ], reprShow, typeShow))
Original file line number Diff line number Diff line change
1
+ opaque type Id = Long
2
+
3
+ class Task :
4
+ opaque type Title = String
5
+
6
+ def a : Title = " a"
7
+
8
+ def run =
9
+ println(" Task.run" )
10
+ println(Macro .getType[Id ])
11
+ println(Macro .getType[Title ])
12
+
13
+ @ main def Test =
14
+ val task = new Task
15
+ println(Macro .getType[Id ])
16
+ println(Macro .getType[task.Title ])
17
+ task.run
You can’t perform that action at this time.
0 commit comments