Skip to content

Commit d903d35

Browse files
Add regression test (#18287)
Closes #18283
1 parent c04d2db commit d903d35

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

tests/run-macros/i18283.check

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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)

tests/run-macros/i18283/Macro_1.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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))

tests/run-macros/i18283/Test_2.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

0 commit comments

Comments
 (0)