Skip to content

Commit 430f910

Browse files
authored
Merge pull request #11519 from dotty-staging/fix-#11161
Add regression test
2 parents 12f34c2 + 8f73130 commit 430f910

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

tests/run-macros/i11161.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Shape$Circle
2+
Shape$Circle

tests/run-macros/i11161/Macro_1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted._
2+
import scala.reflect.ClassTag
3+
4+
inline def showType[T]: String = ${ showTypeImpl[T] }
5+
6+
private def showTypeImpl[T: Type](using Quotes): Expr[String] =
7+
Expr.summon[ClassTag[T]] match
8+
case Some(ct) => '{ $ct.runtimeClass.getName }
9+
case None =>
10+
import quotes.reflect._
11+
report.throwError(s"Unable to find a ClassTag for type ${Type.show[T]}", Position.ofMacroExpansion)

tests/run-macros/i11161/Test_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
enum Shape:
2+
case Square(width: Int, height: Int) extends Shape
3+
case Circle(radius: Int) extends Shape
4+
5+
@main def Test: Unit =
6+
println(showType[Shape.Circle])
7+
println(classOf[Shape.Circle].getName)
8+

0 commit comments

Comments
 (0)