diff --git a/tests/run-macros/i11161.check b/tests/run-macros/i11161.check new file mode 100644 index 000000000000..185364ca1121 --- /dev/null +++ b/tests/run-macros/i11161.check @@ -0,0 +1,2 @@ +Shape$Circle +Shape$Circle diff --git a/tests/run-macros/i11161/Macro_1.scala b/tests/run-macros/i11161/Macro_1.scala new file mode 100644 index 000000000000..c189eaac46d3 --- /dev/null +++ b/tests/run-macros/i11161/Macro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted._ +import scala.reflect.ClassTag + +inline def showType[T]: String = ${ showTypeImpl[T] } + +private def showTypeImpl[T: Type](using Quotes): Expr[String] = + Expr.summon[ClassTag[T]] match + case Some(ct) => '{ $ct.runtimeClass.getName } + case None => + import quotes.reflect._ + report.throwError(s"Unable to find a ClassTag for type ${Type.show[T]}", Position.ofMacroExpansion) diff --git a/tests/run-macros/i11161/Test_2.scala b/tests/run-macros/i11161/Test_2.scala new file mode 100644 index 000000000000..c7626d4d4024 --- /dev/null +++ b/tests/run-macros/i11161/Test_2.scala @@ -0,0 +1,8 @@ +enum Shape: + case Square(width: Int, height: Int) extends Shape + case Circle(radius: Int) extends Shape + +@main def Test: Unit = + println(showType[Shape.Circle]) + println(classOf[Shape.Circle].getName) +