From f347d70865ecc2d6c803bc81ab42d9bf1f7920da Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 25 Jul 2023 13:14:57 +0200 Subject: [PATCH] Add regression test Closes #18283 --- tests/run-macros/i18283.check | 5 +++++ tests/run-macros/i18283/Macro_1.scala | 14 ++++++++++++++ tests/run-macros/i18283/Test_2.scala | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/run-macros/i18283.check create mode 100644 tests/run-macros/i18283/Macro_1.scala create mode 100644 tests/run-macros/i18283/Test_2.scala diff --git a/tests/run-macros/i18283.check b/tests/run-macros/i18283.check new file mode 100644 index 000000000000..212aad48383c --- /dev/null +++ b/tests/run-macros/i18283.check @@ -0,0 +1,5 @@ +(Test_2$package.Id,Test_2$package.Id,scala.Long) +(task.Title,task.Title,task.Title) +Task.run +(Test_2$package.Id,Test_2$package.Id,Test_2$package.Id) +(Task.this.Title,Task.this.Title,java.lang.String) diff --git a/tests/run-macros/i18283/Macro_1.scala b/tests/run-macros/i18283/Macro_1.scala new file mode 100644 index 000000000000..5fc0145d28a2 --- /dev/null +++ b/tests/run-macros/i18283/Macro_1.scala @@ -0,0 +1,14 @@ +import scala.quoted.* + +object Macro: + transparent inline def getType[T] = + ${ getTypeImpl[T] } + private def getTypeImpl[T: Type](using Quotes): Expr[Any] = + import quotes.reflect.* + + val tpe = TypeRepr.of[T] + val reprShow = tpe.show + tpe.asType match + case '[t] => + val typeShow = TypeRepr.of[t].show // dealiased type + Expr((Type.show[T], reprShow, typeShow)) diff --git a/tests/run-macros/i18283/Test_2.scala b/tests/run-macros/i18283/Test_2.scala new file mode 100644 index 000000000000..083040b60dac --- /dev/null +++ b/tests/run-macros/i18283/Test_2.scala @@ -0,0 +1,17 @@ +opaque type Id = Long + +class Task: + opaque type Title = String + + def a: Title = "a" + + def run = + println("Task.run") + println(Macro.getType[Id]) + println(Macro.getType[Title]) + +@main def Test = + val task = new Task + println(Macro.getType[Id]) + println(Macro.getType[task.Title]) + task.run